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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Mon Jun 08, 2009 10:31 pm   

recursive expansion of %i to local var: help please
 
$list1={word1|word2|word3}
$list2={word4|word5|word6}

$difflist={list1|list2}
$nl=word4

#FORALL $difflist {
#IF (%ismember($nl, $%i)) {#show YAY!!!!!}
}

I want to loop through $difflist, testing to see if the string in $nl is present in each of the lists of the same name as %i.

I have tried:

%eval($%i)
$%eval(%i)
%eval($%eval(%i))
and several other similar combinations. I've experimented with %expand as well.

Does anyone know if this is possible? I have a workaround using #until and #switch, but the above #forall loop will be much more efficient, and this script has to be as efficient as possible, since it is already going to be 3 nested loops - I don't want to stick an inefficiently scripted #until loop inside it.
_________________
Athlon 64 3200+
Win XP Pro x64
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Jun 09, 2009 12:56 am   
 
Try ${%i}?
_________________
EDIT: I didn't like my old signature
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Tue Jun 09, 2009 5:19 am   
 
Yeah. I did try that, but it doesn't like that inside the expression of an #IF statement.
_________________
Athlon 64 3200+
Win XP Pro x64
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Tue Jun 09, 2009 6:23 am   
 
I'm not sure what you're doing here. There is no need for #Forall anyway.

Just do this?

Code:
$list1={word1|word2|word3}
$list2={word4|word5|word6}
$difflist={$list1|$list2}
$nl=word4
#IF (%ismember($nl, $difflist)) {#show YAY!!!!!}


$difflist is "word1|word2|word3|word4|word5|word6" not "$list1|$list2"

Output:

YAY!!!!!
Reply with quote
Caled
Sorcerer


Joined: 21 Oct 2000
Posts: 821
Location: Australia

PostPosted: Tue Jun 09, 2009 3:09 pm   
 
It matters whether the value of $nl comes from $list1 or $list2, and the current value of %i is my reference to that. I may have confused the issue by simplifying the whole script so much.

The name of the first list that contains $nl, is also the name of the cure class that I wish to use to cure it. #break would be used to end the loop the moment a successful match is found, and no further calls to a record is necessary, because the value of %i is all I need.

replace #show Yay!!!!
with
cure $nl %i
cure stupidity herb
or
cure stupidity focus

I came up with another way to do the whole script. I'm just using a more complicated expression in my #until loop, and a #switch inside it rather than the #forall. I've been echoing a timer and with no afflictions it runs in 5ms, and with 5-6 afflictions it runs at about 50ms, so I'm happy with that. (The until loop runs until all afflictions or cure types are exhausted).

I would still like to know if this kind of recursion is possible. I often use naming systems to cut down on decision making, but I have had problems using them with %i in the past as well as now. This would be more efficient than the way I have done it, and while a script time of < 50ms means it is pretty inconsequential, I do enjoy making things more efficient.
_________________
Athlon 64 3200+
Win XP Pro x64
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Jun 09, 2009 4:35 pm   
 
You cannot do this kind of indirection with local variables. There is no syntax like ${%i}. That only works with normal variables. Local variables are very limited in what they can do because they only exist within the local execution stack. I might be able to add a function in the future like %local(name) that will retrieve the value of a local variable given it's name. But this will defeat much of the speed advantage of local variables since the reference won't be able to be compiled and will have to be evaluated at runtime and look up a variable reference by name.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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