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


Joined: 19 Nov 2006
Posts: 40

PostPosted: Sat Dec 30, 2006 11:08 pm   

Setting one session's variable to an item from another array
 
All of my sessions have a variable @Mob that I want to set using an array from one of the sessions.

One character has a variable called MobList and a variable called MobNumber. When I try this command:

:Mob = %item( @MobList, @MobNumber)

the current session sets the Mob variable appropriately, but the other sessions set Mob to an empty value. I'm assuming this is because the other sessions do not have access to MobList or MobNumber. How can I send the value of %item across to the other sessions?
In contrast to these results, I have an alias called MobIs which successfully sets the Mob variable for everyone.

:Mob = %1

Does anyone know how to resolve my issue? (other sessions not receive data from %item results)
Does anyone know why a wildcard appendage to an alias works, but using %item does not?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sun Dec 31, 2006 11:12 am   
 
The reason the alias works is because the %1 is expanded before the command is run, so the sessions don't see %1, they see the parameter you entered.

Try using <> or [] to cause the %item to be evaluated immediately.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
apfinger
Novice


Joined: 19 Nov 2006
Posts: 40

PostPosted: Sun Dec 31, 2006 11:03 pm   
 
That explains why %1 works, thanks.

However, I tried your suggestion but was unable to resolve my issue.

:Mob = %item( @MobList, @MobNumber)
Here, Mob is set to an empty value

:Mob = <%item( @MobList, @MobNumber) >
Here, Mob is set to < > (empty value surrounded by < >)

:Mob = [%item( @MobList, @MobNumber)]
Here, I get syntax error

:Mob = %expand(%item( @MobList, @MobNumber)
Here, Mob is set to an empty value

:Mob = %expand(%item( @MobList, @MobNumber), 1)
Here, Mob is set to an empty value

:Mob = %expand(%item( @MobList, @MobNumber), -1)
Here, Mob is set to an empty value

I was unable to find documentation to properly explain the many uses of [ ] and < > in their entirety. Could someone point me in the right direction? Perhaps if I understood the purpose of these characters I could understand why I may have misused them in this situation.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Jan 02, 2007 10:58 am   
 
The correct way to do this is with #EXECUTE and #ALL
#EXECUTE {%concat("#ALL Mob=",%item(@MobList,@MobNumber))}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
apfinger
Novice


Joined: 19 Nov 2006
Posts: 40

PostPosted: Wed Jan 03, 2007 3:10 am   
 
Winner!

I'll go read up on #EXECUTE, %concat, and #ALL to see why this statement interprets %item immediately rather than sending it to other sessions before interpreting.

Thanks!
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