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
wth
Novice


Joined: 14 Nov 2001
Posts: 37
Location: Poland

PostPosted: Thu Jun 27, 2002 9:45 pm   

Parameters scope in triggers?
 


#TEMP {foo (*)} {
#VARIABLE tmp "aaa|bbb|ccc|ddd|eee"

#FORALL @tmp {
#SAY %1
}
}
In FORALL loop parameter %1 is from #TEMP parameter not #FORALL - how to make %1 get values from list?

Rgds,



--
Waldek
There are no mistakes, just learning experience
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Thu Jun 27, 2002 9:50 pm   
 
#LOOP, #FORALL use the tracking variable %i. So you would want:

#TEMP {foo (*)} { #VARIABLE tmp "aaa|bbb|ccc|ddd|eee";#FORALL @tmp { #SAY %i }}

If you have loops in loops etc, you would have to save the
previous %i



#LOOP 2 {
#VAR FirstLoop_i %i
#LOOP 2 {
#ECHO First loop: @FirstLoop_i Second Loop: %i
}
}


Ton Diening
Providing untested answers that tend to be
more complicated than others.
Reply with quote
wth
Novice


Joined: 14 Nov 2001
Posts: 37
Location: Poland

PostPosted: Thu Jun 27, 2002 11:26 pm   
 
You didnt understand my problem. In my case #SAY %1 won't output 'aaa', but will output 5 times string which triggered trigger (string from (*)).
So in my case %1 is not scoped from #FORALL but is scoped from #TEMP trigger - something wrong!?

PS. I'm proffesional developer and know many programing languages - zMud is only one script language which I know, but sometimes works, ekhm... strange

Best rgds,

--
Waldek
There are no mistakes, just learning experience
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jun 27, 2002 11:32 pm   
 
That is because %1..%n is used to refer to values matched by the pattern of the trigger and that zMUD stores because you told it to do it. If you look at Ton's reply, you'll see that inside the #FORALL loop you need to use %i not %1 to refer to the current iteration. That is, it's:
#VARIABLE tmp "aaa|bbb|ccc|ddd|eee"
#FORALL @tmp {#SAY %i}

not:
#VARIABLE tmp "aaa|bbb|ccc|ddd|eee"
#FORALL @tmp {#SAY %1}

no matter if it is all by itself or inside a trigger/alias/macro/etc.

Kjata
Reply with quote
wth
Novice


Joined: 14 Nov 2001
Posts: 37
Location: Poland

PostPosted: Thu Jun 27, 2002 11:38 pm   
 
Yes - sorry for problem - I've just found this error by myself.
I'm using temp trigger in alias so each parameter I have to write as %%1 or %%i and this little embarassed me.
Now everything is ok.

Rgds,

--
Waldek
There are no mistakes, just learning experience
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