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
divinesnoop
Newbie


Joined: 09 Jan 2005
Posts: 5

PostPosted: Sun Jan 09, 2005 12:39 am   

variable in #forall
 
I'm trying to do something like this.

#forall (@list) {
#var value @%i_value
#if (@value > X) {#sa Hi}
}

I can use @%1_value in triggers, but i can't use %i in a #forall it
just ends up becoming silly.

Anyhoo, if someone has an idea of what i'm wanting to do and knows
how to solve it, feel free to help me out.

**EDIT**
Nevermind, i figured out a way. Ugly, but works =)
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sun Jan 09, 2005 1:17 am   
 
This was an interesting problem for me
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere
Reply with quote
misterbalrog
Apprentice


Joined: 26 Oct 2004
Posts: 108

PostPosted: Sun Jan 09, 2005 2:05 am   
 
here's a solution I've used for a poker game of mine that uses variable-variables..
WhereI've done this to test..

#var test {test1|test2|test3}
#forall @test {#if (%eval(@%eval(%i+"_value")) == "1") {#echo yay}}

Meaning I eliminated the whole #var value thingie and just did the if statement directly.

You could instead of '== "1"' put your '> X' ..
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Sun Jan 09, 2005 3:50 am   
 
%i_value is undefined. To get %i with _value appended, you have to specify how much of the string the % refers to.

#forall (@list) {
#var value @%{i}_value
#if (@value > X) {#sa Hi}
}
_________________
LightBulb
Senior member

Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious.
Reply with quote
misterbalrog
Apprentice


Joined: 26 Oct 2004
Posts: 108

PostPosted: Sun Jan 09, 2005 4:02 am   
 
Lightbulb, Ah... well for some reason, zMUD is selective as to when that is applicable for me. Even if it's the same code, sometimes it will not just compute the same at diff times.

Such things I tend to avoid afterwards... and one such is the "selective-expansion" with brackets thus I had totally forgotten about it.
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sun Jan 09, 2005 4:10 am   
 
Sorry about the other reply but I am having tech problems.

Anyways I attempted this proble from alot of different angles and it seems that the problem is using %i with _

I tried the one Lightbulb suggested but it did not work.

I was able to come up with a work around for you though.
Code:

#var storge {_value}
#forall (@list) {#forall (@list) {#var value %i@storage;#if @{@value}=X {#sa hi} {no} }}


I tested this and it worked for me
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Sun Jan 09, 2005 6:57 am   
 
This is how it should be done, period.

#forall @list {#if (@{%{i}_value} > X) {#sa Hi}

Wink
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Sun Jan 09, 2005 9:40 am   
 
Do not use PEGA'S
It does not work in the future he should probably test it first.
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Sun Jan 09, 2005 10:02 am   
 
I tested it, and it works for me. If it does not work for you, my guess is you did something wrong in another part of your script.

Cool
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Sun Jan 09, 2005 10:29 am   
 
Unexpected results? I think megamog75 is encountering a nesting problem. You have to watch for that.

%i and @{%{i}_value}
    or
%%i and @{%{%i}_value}
Reply with quote
misterbalrog
Apprentice


Joined: 26 Oct 2004
Posts: 108

PostPosted: Sun Jan 09, 2005 1:31 pm   
 
Executed:
#var test {test1|test2|test3}
#var test2_value 2
#forall @test {#echo @%{i}_value}

Result:
Code:

2



#forall @test {#echo %{i}_value}

Code:
test1_value
test2_value
test3_value


#forall @test {#echo @{%{i}_value}}

Code:

2



Meaning they've all worked. If anything, Pega's done something wrong with the simpler %{i}_value if it did not work for him. Or wait, could it be... that zMUD's buggy? :O

Anyway, Pega, why should anyone use -that- version if the %{i}_value is simpler to use? There's no reason to add more to it unless necessary (which it isn't now..)
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Sun Jan 09, 2005 2:40 pm   
 
misterbalrog wrote:
Meaning they've all worked. If anything, Pega's done something wrong with the simpler %{i}_value if it did not work for him. Or wait, could it be... that zMUD's buggy? :O

Anyway, Pega, why should anyone use -that- version if the %{i}_value is simpler to use? There's no reason to add more to it unless necessary (which it isn't now..)

    misterbalrog wrote:
    here's a solution I've used for a poker game of mine that uses variable-variables..
    WhereI've done this to test..

    #var test {test1|test2|test3}
    #forall @test {#if (%eval(@%eval(%i+"_value")) == "1") {#echo yay}}

    Meaning I eliminated the whole #var value thingie and just did the if statement directly.

    You could instead of '== "1"' put your '> X' ..

    misterbalrog wrote:
    Lightbulb, Ah... well for some reason, zMUD is selective as to when that is applicable for me. Even if it's the same code, sometimes it will not just compute the same at diff times.

    Such things I tend to avoid afterwards... and one such is the "selective-expansion" with brackets thus I had totally forgotten about it.

Hope that helps. Rolling Eyes
Reply with quote
misterbalrog
Apprentice


Joined: 26 Oct 2004
Posts: 108

PostPosted: Sun Jan 09, 2005 6:48 pm   
 
quoting my own words and only adding "Hope that helps" is in no way a satisfactory reply.

The %eval stuff is not "valid" since I corrected myself with the last sentence you quoted and recognized that there is an alternative, only that it has not worked for me previously all that well.

And I also said in the first quote you've pasted that zMUD is buggy in that sense sometimes, so I am once again pointing it out and fully aware of it. So the meaning behind your post eludes me. Please make some more useful posts than quoting alot of stuff in a miss-guided order.
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Mon Jan 10, 2005 4:12 am   
 
As lightbulb stated %{i}_value is the way to do it. It is not buggy {}'s are for grouping they do not perform expansion or evaluation.

But on another note Have you tried using a data record? From this small portion of script it might suit a better purpose.
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Mon Jan 10, 2005 5:20 am   
 
The additional { }'s were meant to standardize the evaluation for indirect access of variables.

In this case, it was for the set of @{%{i}_value} variables, while @list is in effect a list of pointer offsets.

misterbalrog lamented about zMUD being selective as to when expansion was applicable to him.

and using the @%{i}_value variable as such can be ambiguous if gone unchecked.

I think that the @{%{i}_value} is more flexible than a data record, but a data record may suffice depending on the situation. *shrug*

Smile
Reply with quote
megamog75
Enchanter


Joined: 20 Nov 2002
Posts: 627
Location: USA

PostPosted: Mon Jan 10, 2005 5:43 am   
 
Pega, no disrespect but the reason I said not to use you script was because you left out the end } to inclose your script.

I didn't have it wrong, it simply did not work.

I tested the others and they worked pretty good for me, however when I was working the problem I tried them and they did not work lending to the statment that sometimes zmud does something right about 1 million times and then once just messes up.
_________________
megamog75 Smile
I will do this.Nothing in my life matters except this.No moment in my life exists except this moment.I am born in this moment, and if I fail, I will die in this moment. Raistlin Majere
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Mon Jan 10, 2005 11:35 am   
 
megamog75 wrote:
Pega, no disrespect but the reason I said not to use you script was because you left out the end } to inclose your script.
I didn't have it wrong, it simply did not work.

You are right, a closing } was left out. I accidentally left out the closing bracket when dressing up the internal variable which was the gist of my suggestion - the representation of that variable with %i, and it was highlighted. misterbalrog figured it out. I admit that that suggestion is not user-friendly, but this is not the finished script forum and that single line alone does not operate on its own.

I saw no need for an explanation at that point of time, since it can be quite involved especially when not knowing the aptitude of the audience.

megamog75 wrote:
I tested the others and they worked pretty good for me, however when I was working the problem I tried them and they did not work lending to the statment that sometimes zmud does something right about 1 million times and then once just messes up.

My previous message (Posted: 10 Jan 2005 13:20) explicitly stated why the others may mess up.

I may post an illustration later if time and motivation permits.

Regards
Reply with quote
Pega
Magician


Joined: 08 Jan 2001
Posts: 341
Location: Singapore

PostPosted: Mon Jan 10, 2005 11:16 pm   
 
Tell you what, I have not been scripting on zMUD that much in recent years, and the problems that I saw several years ago are not applicable now. Perhaps the extra braces for variable representation are unnecessary or they may apply in other areas.

My bad.

As far as I can see at this time,

@%{i}_value and @{%{i}_value}

are in effect identical and the braces are redundant.

Best regards
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Jan 11, 2005 4:41 am   
 
Well I suggested a data record because from the looks of it he is just trying to use linked variables which can lead to multiple variables and then trying to remember them all while a data record would group them into one var which could be looped with a #LOOPDB

instead of having
this={one|two|three|four}
one_value=1
two_value=4
.....

you would have something like this

Values.one=1
Values.two=2

It could be just me but I find it easier when the variables are grouped :P
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
darkspot
Apprentice


Joined: 29 Jul 2002
Posts: 105

PostPosted: Thu Jan 13, 2005 4:55 pm   
 
I was playing with something similair with #forall's and one thing I did notice. %eval solves some problems, but also isn't needed other times. The major difference was where things appeared. Command line, in an alias, in a trigger, in a alias used by a trigger. They didn't all play nicely together.
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