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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
vinceres
Newbie


Joined: 09 Dec 2006
Posts: 4

PostPosted: Fri Dec 15, 2006 12:12 am   

[1.23] %i - not sure what else to call it
 
I have just a question with a coding issue concerning the system variable %i - here is what I'm doing.


Database variable : fighting
KEY VALUE
------------------------
keys Jester


Databast variable: class_skills
KEY VALUE
-------------------------
Jester csPranks|csTarot|csVodun_Puppetry

Button : btn_opps
-----------------------
#if (%numitems( %db( @fighting, keys)) > 0) {#forall {%db( @fighting, keys)} {testing %i}}

Alias: testing
----------------
#if (%iskey( @class_skills, %1)) {#forall {%db( @class_skills, %1)} {#show %i}}


--------------------------
When I hit the button on Zmud...the output shows:
csPranks
csTarot
csVodun_Puppetry

When I hit the button on Cmud...the output shows:
Jester
Jester
Jester

For some reason the %i system variable is maintaining "Jester" from the first time %i was used in the button. the button uses the alias "testing" which is supposed to loop through the "class_skills" variable database and identify the individual values, but it doesn't. Any ideas on how to make it work, if its even possible?
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Dec 15, 2006 12:56 am   
 
Hmm, I can't find a way to get it working in CMUD either
To make it a little clearer I just made two aliases and didn't bother with #IF statements

Code:
#VAR fighting {}
#ADDKEY fighting keys Jester

#VAR class_skills {}
#ADDKEY class_skills Jester csPranks|csTarot|csVodun_Puppetry

#ALIAS blah {
#say %db( @fighting, keys)
#forall {%db( @fighting, keys)} {testing %i}
}
#ALIAS testing {
#say %db( @class_skills, %1)
#forall {%db( @class_skills, %1)} {#show %i}
}


It looks like it's the %1 that's causing a problem too
If you run blah it will call
'testing Jester'

But if instead of letting blah call testing you just type on the command line 'testing Jester' then it works...

Could be a bug
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Dec 15, 2006 2:11 am   
 
We've actually talked about this in other threads before.

In CMUD, %i refers to the outer-most loop. In your example, the "blah" alias calls the "testing" alias within a loop, and then the "testing" alias has it's own nested loop. So %i still refers to the outer loop in "blah". To access the inner loop in "testing" you need to use %j

I know this isn't very intuitive, and I will be looking for a way to improve it in the future. But that's how it works for now.
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Fri Dec 15, 2006 2:20 am   
 
Ahh, thanks for the clarification.

I can see a problem with the current syntax
If %i is changed to %j in the 'testing' alias then all works fine if called by 'blah'
The problem though is what if I just wanted to 'testing Jester' direct from the command line - changing %i to %j breaks the alias when it's not a nested loop

I'm guessing that's one of the reasons you're looking to improve it - just wanted to mention it anyway though

Guinn
_________________
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 Dec 15, 2006 2:23 am   
 
I found a way around this in my script. I created a string list in one alias using a local variable and then passed that as one argument to the second alias. That way I don't have two nested loops in two different aliases and I don't have to worry about whether I need %i or %j, meaning that I can still use each alias in different situations.

To illustrate using this specific case, here's what I'd do to change the btn_opps code and make the testing alias work:

Code:
#local $opps;#if (%numitems(%db( @fighting, keys)) > 0) {#forall {%db(@fighting, keys)} {$opps = %additem(%i, $opps)};testing $opps}
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum 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