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
empyrealhell
Newbie


Joined: 08 Feb 2007
Posts: 3

PostPosted: Thu Feb 08, 2007 8:15 pm   

Asynchronus While Loop
 
I am trying to setup a trigger that will wait for a certain condition to be met, then execute a command. I want it to do several of these in a row without having to setup a finite state machine. Here's what I had for an idea

#ALIAS Execute {
#while (@Condition) {#WAIT 500}
DoCommand
#while (@Condition) {#WAIT 500}
DoCommand
}
#TRIGGER ^You feel rested.$ {#VAR Condition 0}

What I want to know is 1) will the while loops pause the execution of that alias without halting the entire application? and 2) will this cause these two commands to be executed .5 seconds apart from eachother so long as the condition variable is false? If the condition variable is set to true in between the first command and the second command (before the while loop) will it pause again until that value changes? and will it be able to change while the alias is looping?

I know that if this was a standard procedural environment that would do it, but I'm not sure how these aliases work with the flow of the program.
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Feb 08, 2007 8:26 pm   
 
#WAIT is evil, try not to use it (many posts on the merits of #ALARM vs #WAIT)

I'd be more tempted to use

#ALIAS Execute {
#IF (@Condition) {
DoCommand
#ALARM myAlarm {+0.5} {Execute}
}
}
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Feb 08, 2007 8:33 pm   
 
Think I misunderstood what you're after. This might be better.
It'll do both commands if @cond is true, not checking inbetween whether cond changes. If you wanted to check whether #COND changes then you'd need to replace 'DoCommand2' with '#IF (@condition) {DoCommand2}'

#ALIAS Execute {
#IF (@Condition) {
DoCommand1
#ALARM myAlarm1 {+0.5} {DoCommand2}
#ALARM executeAlarm {+1} {Execute}
}
}
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
empyrealhell
Newbie


Joined: 08 Feb 2007
Posts: 3

PostPosted: Thu Feb 08, 2007 9:29 pm   
 
Yeah, I thought about that, the problem is this is quite a complicated little piece of scripting. There about 45 of those that I need to do in sequential order, and the time in between them is going to vary based on the results of the last option.

So, lets say we get rid of the evil wait (though it was my understanding it was designed to make a loop have a delay, which is what I'm doing with it) and leave the while loop empty.

#ALIAS Execute {
...
#VAR flgConditionalFlag 1
#WHILE (@flgConditionalFlag) { }
DoSomething
#VAR flgConditionalFlag 1
#WHILE (@flgConditionalFlag) { }
...
}
#TRIGGER ^Some Text Here.$ {#VAR flgConditionalFlag 0}

The reason I don't want to use alarms is because I'm doing this inside of a loop
Basically this is what I'm trying to do
This is a defense system check for Achaea
I have three lists
One contains what defenses I should have up at all times
One has what the process I need to use to put each defense up
and One captures the data from the DEF command and puts it into a list

Once the DEF command is processed the list is filled with data and this alias is run
It loops through each line in the required defense list and checks it against each of the defenses in the filled list
Each defense that matches is removed from the list of required defenses
After it has looped through both lists I will have a list remaining with all of my defenses that it didn't detect on me
At that point I want it to loop through each one and cast it on myself

The conditional variable is my state of equilibrium. For each command I cast it will remove my equilibrium, which will be restored an amount of time later that depends on the spell cast.

What I want this to do is cast the first spell, then sit and wait until equilibrium is back and then cast the next one. The reason I don't want to use alarms is that I like to keep all of my code in the same place as it's easier to manage that way, and this defense check is only part of a larger system. This code is in a function that is alarmed every .1 seconds and I just use my triggers to throw up flags for different things. So I understand the issue most people have with waits but I don't necessarily need it to wait .5 seconds, I just need it to idle until that condition is met.
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Feb 08, 2007 9:50 pm   
 
If there's a unique message for a successful cast of each spell then it should be fairly straightforward.

You could generate the list from a key/val variable with something like
#loopdb {importantSpells} {#if (@val = 0) {#ADDITEM spellsList %key}}

once a spell is successfully cast then you remove that from your generated stringlist of spells remaining using #DELITEM. Once you regain equilibrium then you just cast the first item on the list
%item(spellsList,1)

I try and avoid casting multiple things at once in a system like Achaea where there is some sort of balance that prevents stacking commands - might just be because the game I play is a bit buggy and lags often so commands using wait in a loop would probably get eaten.

(I've not tested the code, so syntax might be slightly off)
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
empyrealhell
Newbie


Joined: 08 Feb 2007
Posts: 3

PostPosted: Thu Feb 08, 2007 9:55 pm   
 
Right, that's why I was using the while command

All I really wanted to know was if I could do this

#WHILE @condition { }

and it would sit at that location in my alias until the condition was false, and if the triggers that would change that variable would still be able to fire.
I would test this myself but I'm not at a location where I can (On my laptop at work so I can't install ZMud)

My trigger fires on the "you have recovered equilibrium" message, so it would sit at that while command until that trigger fires, changing the value of @condition.
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Feb 08, 2007 10:48 pm   
 
It sounds like you really need an expression trigger.
Take a glance at
http://forums.zuggsoft.com/phpbb/viewtopic.php?t=13831

to see if it seems appropriate
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Fri Feb 09, 2007 7:18 pm   
 
You should see the way I do defenses in Acropolis (my Achaea combat system, free download, no longer supported by me). Queue up defenses in balance queues (string lists), execute the first one (removing it from the string list), when you recover whatever balance (eq, bal, herb, salve, etc), pop off the next on the list and execute it. When you have nothing left in the queue, you're done. I execute all the balances in parallel, so you can put up salve defenses while you put up herb defenses, balance defenses, etc. I think it's pretty slick... and not a single #WAIT anywhere in my scripts, ever!
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Feb 09, 2007 7:26 pm   
 
Aint that what I suggested? ;)
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
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