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
musishun00
Wanderer


Joined: 16 Dec 2003
Posts: 77
Location: USA

PostPosted: Tue Jan 20, 2004 12:31 am   

Nested variables?
 
I'm trying to write a script that will go a random direction out of a room. I've got variables for all the room numbers that I want to do, as well as all of the rooms' exits, but here's where I have problems. This is basically what I have so far. Let me know if you need further explanation. Hopefully, this will kind of explain itself when you see my settings below.

#ECHO Current room is ~*~*@current_room~*~* (This will always be an integer)

#TRIGGER {Current room is ~*~*(%n)~*~*} {#var temp_curr_room %1}

#1 {%item(@room_'@temp_curr_room'_exits,%random(1,%numitems(@room_'@temp_curr_room'_exits)))}

Basically, what I'm trying to do is get the integer value (@temp_curr_room) to expand inside the @room_##_exits variable. That way, I can randomize the exit based on a random number between the choices in @room_25_exits (just an example).

So how can I get the temp variable to expand inside the other variable, thereby completing it? I'm totally stumped on this one, so I appreciate any help. Thanks!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Jan 20, 2004 12:03 pm   
 
According to the help for variables, the proper thing to use are braces.

@room_@{temp_curr_room}_exits
Reply with quote
musishun00
Wanderer


Joined: 16 Dec 2003
Posts: 77
Location: USA

PostPosted: Tue Jan 20, 2004 7:52 pm   
 
Hmmm... it doesn't seem to work. I'm not getting errors anymore, but the '_exits' part isn't being treated as part of the variable. Here's what I'm looking at:

#var new_room %random(1,%numitems(@room_@{temp_curr_room}_exits))
@current_room = %arrget(@room_@{temp_curr_room}_exitnumbers,@new_room)
#1 {%arrget(@room_@{temp_curr_room}_exits,@new_room)}

I'm stumped... I'm gonna keep trying things, and see if they work. Thanks for more help in advance!
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Tue Jan 20, 2004 10:52 pm   
 
Try enclosing the entire variable name with {}:
Code:
#var new_room %random(1,%numitems(@{room_@{temp_curr_room}_exits}))
@current_room = %arrget(@{room_@{temp_curr_room}_exitnumbers},@new_room)
#1 {%arrget(@{room_@{temp_curr_room}_exits},@new_room)}
Reply with quote
musishun00
Wanderer


Joined: 16 Dec 2003
Posts: 77
Location: USA

PostPosted: Thu Jan 22, 2004 9:55 am   
 
Ok. Here's the settings I have for the current room. The braces highlighted in red should be recognized as part of the variable, but they aren't. I've tried the braces in all different places, but they just don't seem to work. I want the script to grab a random number from 1-x, where x is the number of items in the roomexit_xx and roomexitnum_xx variables. So, in this instance, it should pick between 1 and 5. Then I want it to send that command to the mud from the roomexit_xx variable, and set the current_room variable to be equal to the same position in the roomexitnum_xx variable.

#ALIAS newroom {#ECHO Current room is ~*~*@current_room~*~*}
#ALIAS newroom2 {#VAR new_room {%random(%numitems({@roomexit_@{temp_curr_room}}))};current_room = %arrget({@roomexitnum_@{temp_curr_room}},@new_room);#SEND {%arrget({@roomexit_@{temp_curr_room}},@new_room)}}
#TRIGGER {Current room is ~*~*(%n)~*~*} {#VAR temp_curr_room %1;newroom2}

#VAR current_room 2
#VAR roomexitnum_02 {1|5|3|54|42}
#VAR roomexit_02 {n|e|s|u|d}


Example:

Current room is **2**
(random number picked is 4)
current_room should now equal 54
The command "u" should be sent to the mud, moving me up.

I hope this makes sense, and someone can help me figure out what is going wrong with it. I've turned this over in my head so much that I think I'm going to go crazy.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jan 22, 2004 12:14 pm   
 
You using %arrget with a list variable. The correct function to use would be %item.

Also braces used with the @ should surround only the variable name:
@{roomexit_@{temp_curr_room}}
In this particular case neither set of braces is necessary, because you renamed your variable from your first script to simpler names that the parser will figure out without help.
Reply with quote
Danlo
Magician


Joined: 28 Nov 2003
Posts: 313
Location: Australia

PostPosted: Thu Jan 22, 2004 12:23 pm   
 
As I said earlier, use braces around the variable name: @{room_@{temp_curr_room}_exits}
not {@room_@{temp_curr_room}_exits}.

Second problem: roomexitnum_02. Your trigger will set temp_curr_room to 2, not 02. That means the last part of your script is referencing to variable Roomexitnum_2, not Roomexitnum_02.

Third problem: You're using %arrget when only %item is needed.

In all, rename your variables and change your script to:

#ALIAS newroom {#ECHO Current room is ~*~*@current_room~*~*}
#ALIAS newroom2 {#VAR new_room {%random(%numitems(@{roomexit_@{temp_curr_room}}))};current_room = %item(@{roomexitnum_@{temp_curr_room}},@new_room);#SEND {%item(@{roomexit_@{temp_curr_room}},@new_room)}}
#TRIGGER {Current room is ~*~*(%n)~*~*} {#VAR temp_curr_room %1;newroom2}
Reply with quote
musishun00
Wanderer


Joined: 16 Dec 2003
Posts: 77
Location: USA

PostPosted: Thu Jan 22, 2004 8:53 pm   
 
Works like a charm! Thanks much! I knew there was something I was overlooking, and I had a feeling it had to do with the %arrget function, but for some reason I couldn't remember the %item function. Thanks for all your help!
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