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


Joined: 09 May 2016
Posts: 6

PostPosted: Wed Sep 14, 2016 4:32 am   

Using Variable in a FORALL statement
 
Having issues with FORALL. Zmud 7.21.

#IF (@DRAGLISTa="") {#FORALL @DRAGTEMPDIRECTION2 {%i}} {#FORALL @DRAGTEMPDIRECTION2 {drag @DRAGLISTa %i}}

Anytime I use this it makes the %i create a new line, instead of adding it to the drag @DRAGLISTa line. Giving me unwanted results. If I remove the @DRAGLISTa variable, it will then work as it should on same line.

Any tips? The DRAGLISTa variable is simply a stringlist, nothing extra. May contain 0 or multiple names.
Reply with quote
Einder
Novice


Joined: 03 Jan 2008
Posts: 48

PostPosted: Wed Sep 14, 2016 7:55 am   
 
You don'at have your forall statement adding anything to draglista. It should look more like

Code:
#IF (@DRAGLISTa="") {#FORALL @DRAGTEMPDIRECTION2 {DRAGLISTa=%additem(%i, @DRAGLISTa)}}


and since it looks like you want to use DRAGLISTa next, you don't need a forall on DRAGTEMPDIRECTION2, you need whatever you item is going to be and to do something that looks more like this:

Code:
#IF (@DRAGLISTa=%null) {#FORALL @DRAGTEMPDIRECTION2 {DRAGLISTa=%additem(%i, @DRAGLISTa)}} {#FORALL @DRAGLISTa {drag (item|person|whatever) %i}}


The first check will see if the draglist is empty, then the first forall will fill the list from a secondary list, the last forall will drag whatever it is you want dragged in the directions in the list if it's not empty.
Reply with quote
Keltec
Newbie


Joined: 09 May 2016
Posts: 6

PostPosted: Wed Sep 14, 2016 9:14 am   
 
Well basically the DRAGTEMPDIRECTION2 is a already compiled directions I wanted to use. Which are reversed not only in order but directions as well, this is already done. The DRAGLISTa is a list of names in a stringlist where | is replaced with DRAG. So basically the DRAGLISTa is ready to go as is, I just need it to relay the directions from DRAGTEMPDRIRECTION2 as 1 line for each direction in DRAGTEMPDIRECTION2. Which is why I am using the FORALL command. Maybe LOOP would be better suited? I just only know that FORALL will create a new line per item in a string list, but it doesn't if I throw a VARIABLE in there.

For example. It looks like this if I have a variable with %i, say I'm moving east then north in DRAGTEMPDIRECTION2.
drag Name drag Namea drag Nameb drag Namec
e
drag Name drag Namea drag Nameb drag Namec
n

Example 2. But what I want is this, which is how FORALL works if I do not put variable next to %i.
drag Name drag Namea drag Nameb drag Namec e
drag Name drag Namea drag Nameb drag Namec n

I wasn't trying to add anything to DRAGLISTa, that variable is already how I want it. I'm trying to add a single direction from multiple directions stored into DRAGTEMPDIRECTION2. I want each direction in DRAGTEMPDIRECTION2 to be added to the end of DRAGLISTa, but only 1 direction per line used with DRAGLISTa or the game rejects it. Which is why I was using the FORALL command and not populating DRAGLISTa. For that command does do what I want, it just creates a new line if I put a variable next to %i for whatever reason, which is not what I want.

I'll toy with what you said, see if I can get it working. But feel maybe you didn't understand me. I very much appreciate the input though, thank you.

-EDIT Ok think I found my problem. Was due to my method of testing the script. The DRAGLISTa variable I manually populated with names, which did not create a string list, when I manually created it to a string list. It worked. But I'll still take input for better methods.
Reply with quote
Einder
Novice


Joined: 03 Jan 2008
Posts: 48

PostPosted: Wed Sep 14, 2016 10:37 am   
 
If your trying to execute them consecutively, I think #loop is what you want, you can check out this post: http://forums.zuggsoft.com/forums/viewtopic.php?t=9948 to find out more about it
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4689
Location: Pensacola, FL, USA

PostPosted: Wed Sep 14, 2016 1:53 pm   
 
If dragging never fails, you could use something like:

#IF (@DRAGLISTa) {drag @DRAGLISTa %pop(DRAGTEMPDIRECTION2)}
_________________
Discord: Shalimarwildcat
Reply with quote
Keltec
Newbie


Joined: 09 May 2016
Posts: 6

PostPosted: Fri Sep 16, 2016 10:27 am   
 
Thanks I will try the %pop. Then yes dragging never fails, unless you can't drag due to fly, is no dice roll to drag though.

Problem with consecutively with #loop is that it puts it all on one line. I need the DRAGLISTa to be 1 line, but then I need it all said for each direction in DRAGTEMPDIRECTION2. For the DRAGTEMPDIRECTION2 is made from a loop command, then a subchar command to reverse order. But how dragging works in the mud I play, you have to type drag playername drag playername2 direction(insert as many corpses as needed), but if I'm going multiple directions, you have to repeat the drag line with just 1 direction. Thats why I landed on the FORALL command for it does this.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4689
Location: Pensacola, FL, USA

PostPosted: Fri Sep 16, 2016 12:47 pm   
 
i thing i have it..

#IF (@DRAGLISTa) {#WHILE (@DRAGTEMPDIRECTION2) {drag %expandlist(@draglista, " drag ") %pop(DRAGTEMPDIRECTION2)}}

A #FORALL could do the same thing as the #WHILE, just replace the %pop(stuff) with %i.
_________________
Discord: Shalimarwildcat
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