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
shalimar
GURU


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

PostPosted: Fri Feb 02, 2007 10:56 pm   

Variables issue
 
#ALIAS un {
#VAR target %-1
#VAR dostuff {%item( @un, %random( 1, %numitems( @un))) @target}
pounce @target
}

and i have a trigger that does:

#FORALL @dostuff {#EXEC %i}

Mainly the problem is in @dostuff

If done as is, it evaluates with the variable call, not to mention it strips out the space between the ending parenthasis of %item and @target, not what i want.

If i quote the contents to make it a string, or use FUNC instead of VAR, it goes into @dostuff the way i want, but now the FORALL does nothing with @dostuff, it doesnt even spit the string to the MUD.

Any ideas?
_________________
Discord: Shalimarwildcat
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Feb 02, 2007 11:57 pm   
 
Did you try putting curly braces {} around it?
_________________
Asati di tempari!
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 03, 2007 12:35 am   
 
Which 'it' do you mean?
_________________
Discord: Shalimarwildcat
Reply with quote
Zugg
MASTER


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

PostPosted: Sat Feb 03, 2007 12:47 am   
 
Code:
#VAR dostuff {%item( @un, %random( 1, %numitems( @un))) @target}

I don't understand the above line. What is the @target reference doing there by itself? If you are trying to append a space and @target to the results of the %random call, then you need to use %concat explicitly:
Code:
#VAR dostuff {%item( @un, %concat(%random( 1, %numitems( @un)))," ",@target)}

In any case, I think that is where your problem lies. I don't know exactly what it's trying to do, but the syntax you are using is definitely wrong.
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 03, 2007 1:02 am   
 
its for the #forall statement, i want the #forall to process it and sent the results via the #EXEC

and your syntax is wrong there as well Zugg... the concat should come BEFORE the item if your doing it that way, but it does fix the missing space once that is cleared up

but im still having the trouble that it gets evaluated at #VAR definition... i want it to randomize the results each time the #FORALL hits it
_________________
Discord: Shalimarwildcat
Reply with quote
Zugg
MASTER


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

PostPosted: Sat Feb 03, 2007 1:18 am   
 
Sorry, I misunderstood where the %concat was needed.

Yes, #VAR is *always* going to evaluate the value being assigned. That's one of the differences in CMUD mentioned In the Help file Here

If you don't want it to be evaluated, then you must use the #FUNC command instead of #VAR.
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 03, 2007 1:36 am   
 
If you had read my entire first post, you would have seen that i have tried #FUNC already.... I apprechiate your attempt to help, but dont suggest something i've already tried.
_________________
Discord: Shalimarwildcat
Reply with quote
Zugg
MASTER


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

PostPosted: Sat Feb 03, 2007 1:42 am   
 
Yes, I saw that, but I didn't fully understand what didn't work. I was addressing the problem you mentioned with #VAR evaluating. And as I said, #VAR is *always* going to evaluate, so you *must* use #FUNC if you don't want it to do that.

So, that leaves the #FORALL statement. Have you done a simple #SHOW @dostuff to see if it is forming a correct string list? Maybe you need to use %eval(@dostuff) in the #FORALL statement to force it to run the function?

I'm trying to help as much as I can, but you haven't really given us a lot of specifics. Showing us what you think should be stored in @dostuff and compare it to what it stores. Show us the sample output you are trying to get.

The entire script looks very wierd and complicated, so my guess is that there is probably a much better way to do what you are trying to do, so if we had a clue exactly what you were trying to accomplish, it might help. Hopefully one of the other gurus can help you more over the weekend.
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 03, 2007 2:01 am   
 
Okay... i will try to explain better.

@dostuff is a place holder i have to work around RoundTime, or delays before i can perform another command, not all commands induce RT so sometimes i can spit out several before having to wait again

@dostuff is often (in other cases) an array, which is why i use the #FORALL, to loop through it and execute each memeber

I have tried
Code:
#FORALL @dostuff {#EXEC {%eval(%i)}}

as well, but it didnt work either.

I changed it to a #FUNC again to see what was happening.

In the settings editor, the value of @dostuff is what it should be, however, if i:
Code:
#SAY @dostuff

all it returns is a single empty space.

Im not sure if it matters or not, but the @dostuff variable is in a seperate package from the @un and @target variables, both it and the main package can see each ther though.
_________________
Discord: Shalimarwildcat
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Feb 03, 2007 6:20 am   
 
As long as @dostuff is in a global or external module then the script can see it. Anything else and that's the problem. My question is what does @un contain? I'm not sure it matters though, since @target (which is simply %-1) will be delimited by spaces and not pipes. Same when you do your "%item() @target" thing - you'll end up with a list that's separated by spaces. This will totally naff up #FORALL since it'll recieve a list separated by spaces when it wants a list separated by pipes.

For example, you run "un" with the arguments "test1 test2 test3" and you'll end up with @dostuff containing "RandomUnItem Test1 Test2 Test3". When this gets passed to #forall that'll cause problems since it's expecting a string list in the format "RandomUnItem|Test1|Test2|Test3". Use %replace to switch the spaces to pipes when it's passed to #forall (or when it's created if nothing else uses it).
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 03, 2007 8:18 am   
 
un=kick|jab|punch|uppercut|knee|elbow|throw

its a list of unarmed commands...

most offen @target is just a single word as well though, so the worry of it having spaces in there

i think it might be a whole lot easier if i just make this an #alias and pass it @target
it won matter if it evaluates immediatly that way
_________________
Discord: Shalimarwildcat
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Sat Feb 03, 2007 2:48 pm   
 
This worked when I tested it. If you're trying to add multiple items to "dostuff," however, you'll need to use #ADDITEM instead of #VAR.

Code:
#VAR un {kick|jab|punch|uppercut|knee|elbow|throw}
#ALIAS un {
#VAR target %-1
#VAR dostuff {%item(@un, %random(1, %numitems(@un)))" "@target}
pounce @target
}
un Bob
#FORALL @dostuff {#EXEC %i}
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 03, 2007 3:18 pm   
 
do you have @dostuff as well as the #FORALL call in another package to mimic my settings?

when i want mutliple items in @dostuff i just declare it as an array just like your definition of @un, no need to go into #ADDITEM if you know all the members before hand, its more useful for inline creation
_________________
Discord: Shalimarwildcat
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Sat Feb 03, 2007 5:00 pm   
 
I did not put the variables in another package or module, but I think I can help with that, too. Make sure you have the package with the variables checked on the list of "Packages enabled for this package" in the package where your aliases are stored. Select the package in the tree view and you'll see the list of packages. You'll always want to make sure the package with the variables is published globally and not just locally.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Sat Feb 03, 2007 5:14 pm   
 
Larkin wrote:
I did not put the variables in another package or module, but I think I can help with that, too. Make sure you have the package with the variables checked on the list of "Packages enabled for this module" in the module where your aliases are stored. Select the module in the tree view and you'll see the list of packages. You'll always want to make sure the module with the variables is published globally (or externally) and not just locally.

is what I think you meant, Larkin. But from the sound of it, he's already doing this right.
Reply with quote
shalimar
GURU


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

PostPosted: Sat Feb 03, 2007 6:38 pm   
 
Yes, both packages are checked as enabled for each other
@un and @ target are in the 'Combat' class of my main package
the other two are located in the 'FE Mimic' Package available in the package liabrary, which is set to be global.
_________________
Discord: Shalimarwildcat
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