Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: Sat Apr 19, 2003 6:53 pm   

Looping actions with buttons
 
I tried several things to try and get this idea to work, but was unsucessfull. Maybe one of you can help with the basics of it. I am trying to link an repeating action with a button to turn it on and off. The button would start a loop of actions that would repeat itself until the button was pressed again. I can get the looping going, and get it to start on the button press. But I can't seem to get it to stop with the button press. I am unsure if I am doing something wrong with the loop to get it to end or if I am linking up the button to it wrong. So basic format is this:

PressButton(loop begins)
Action
Another Action
etc.....
PressButton(loop stops)

Can anyone think of what I might have done wrong?
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sat Apr 19, 2003 11:12 pm   
 
You didn't use the right commands to stop the loop in the second part of the button.

If you want a real answer, you'll have to provide specifics.

LightBulb
Advanced Member
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: Sun Apr 20, 2003 12:22 am   
 
I was thinking it was the button because I was trying to tie the loop to the button state. It has been a bit since I worked on it, but I hope this makes it a little clearer my intentinos:

Press GuardOn button
Loop:
guard head -- wait 3 sec
guard torso --wait 3 second
guard right arm -- wait 3 sec
guard left arm --wait 3 sec
guard right leg -- wait 3 sec
guard left leg -- wait 3 sec

When the button gets pushed again I'd like this to stop. I thought a WHILE would do it but I can't seem to link that with the button press

I tried having the button press set a variable(gvar) to 0 or 1 and then my loop was: #WHILE (@gvar<>0) but this didn't do it
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Apr 20, 2003 2:30 am   
 
The specifics I meant would be the ACTUAL commands for each button state, as well as the actual commands for any other settings (aliases/triggers/etc) which will be affected by it. There's no way to tell what you're doing wrong without knowing what you are doing.

LightBulb
Advanced Member
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: Sun Apr 20, 2003 5:22 am   
 
Okay...got it so that it stops at the end of the current loop, but can't just get it to stop right out. Also, now my button caption won't change. I'll describe this as best I can, since I didn't enter this from the command line.

Toggle Button
State: Button Up
Caption: Guard On
Script: guardon(for an alias)
State: Button Down
Caption: Guard Off
Script: guard nothing
Advanced:
Variable: gvar

Alias guardon:
#WHILE (@gvar<>0) {
guard head
#WA 3000
guard torso
#WA 3000
guard right arm
#WA 3000
guard left arm
#WA 3000
guard right leg
#WA 3000
guard left leg
#WA 3000
}

As you can probably tell, I am still getting the hang of this all. If someone can also unclutter my alias, I'd be really appreciative.
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: Sun Apr 20, 2003 5:27 am   
 
And sorry...i had indents in there..but they didn't appear.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Apr 20, 2003 6:59 am   
 
The problem is that the variable is only checked at the beginning of the loop, so you can only stop after the end of the loop when it gets checked again. A better solution might be to use an alarm and toggle it on/off with the #T+ and #T- commands.

Toggle Button
State: Button Up
Caption: Guard On
Script:
#VAR GuardIndex 1
#T+ Guard
State: Button Down
Caption: Guard Off
Script:
#T- Guard
guard nothing

Enter this block at the command line:
#CLASS Guard disable
#ALA -3 {#CASE @GuardIndex {guard head} {guard torso} {guard right arm} {guard left arm} {guard right leg} {guard left leg};#ADD GuardIndex 1}
#CLASS 0

Don't worry about indents. The forum strips "excess" spaces.

LightBulb
Advanced Member
NOTE: You might want to swap the captions
Reply with quote
Dumas
Enchanter


Joined: 11 Feb 2003
Posts: 511
Location: USA

PostPosted: Sun Apr 20, 2003 10:01 am   
 
Thanks! that did it and was much simpler. Its been tough learning more about this since the tutorials don't go this in depth.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Apr 20, 2003 2:48 pm   
 
That's true. One good way to learn more is to keep reading this forum. It will give you numerous examples of both good and bad scripts, introduce you to commands you never thought of using, and suggest useful additions to your scripts.

LightBulb
Advanced Member
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net