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


Joined: 07 Jan 2002
Posts: 8
Location: USA

PostPosted: Mon Jan 07, 2002 9:32 am   

@ special character in Vars
 
Trying to assign a variable a value of @B. Helpfiles claim ~@B will do the trick, but unable to get it working...to duplicate:
#var test ~@B;#show @test
shows nothing.
This works in an alias:
#alias test {say ~@B}
There are ways to get around this I know, just curious if it's a bug.
Thanks,

Jason
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Jan 07, 2002 2:10 pm   
 
When I do:
#VAR test ~@B

@B is in fact stored in @test. However, since @B is not defined, doing:
#SHOW @test

will display nothing because it expands @test to @B and tries to expand @B but that variable doesn't exist.

You might try looking into the %expand function which lets you specify how much you want a variable to be expanded before returning its contents.

Kjata
Reply with quote
relic
Newbie


Joined: 07 Jan 2002
Posts: 8
Location: USA

PostPosted: Mon Jan 07, 2002 2:29 pm   
 
Right, it assigns it the value of variable @B, but this is NOT what I want. I want it to be assigned the string @B.
Prefixing @B by ~ should do this according to help files, and it does when used in an alias, but not in this variable.

Jason
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Mon Jan 07, 2002 2:50 pm   
 
For me it does exaclty that.

Do you have variable @B defined? Since when you do:
#SHOW @test

it shows nothing, I'm guessing that @B is not defined and thus it displays nothing.

However, it very well maybe that nothing is being assign to @test. To check this just go into the settings editor and look at what appears under the value field of the variable test. When you do:
#VAR test ~@B

there should appear @B, just like it does for me. If this is so, then the problem is that when you try to show the contents of @test it also expands @B, but since it doesn't exists, it just shows nothin. In this case, %expand comes in handy so you can specify how many levels of expansion you want.

If however, for some reason, @B is being saved into @test when you do:
#VAR test ~@B

then that is very strange because that's not what is supposed to happen. Nevertheless, you can still try using:
#VAR test "@B"

which, in any case, would be the "technically" correct syntax since you are using the quotes to mean it is a literal string.

Kjata
Reply with quote
relic
Newbie


Joined: 07 Jan 2002
Posts: 8
Location: USA

PostPosted: Mon Jan 07, 2002 2:58 pm   
 
Let me explain a bit more.
When I reference that variable, I want the string @B to be returned, because I want @B to be sent to the mud. My mud uses that code to color-code as Dark Blue. I don't want @B expanded as anything else, for this purpose I do not want it to be a variable.
Did you try the alias I put in my first posting? That is the behavior I am looking for in the variable.

Jason
Reply with quote
Charbal
GURU


Joined: 15 Jun 2001
Posts: 654
Location: USA

PostPosted: Mon Jan 07, 2002 3:07 pm   
 
Whenever @b is in sequence, the parser will try to substitute b in to expand it. You can mess around with expansion settings but that might break other scripts.

I tried
#var test ~@b
and
#var test ~~~@b
of which neither worked :b

But this does:
#var test @~~b

The ~~ is evaluated to ~ when assigning the variable so you have @~b as the value. When it is used in a script, the ~b turns into b so you have final text of @b, exactly what you want.

- Charbal
Reply with quote
TaisharMalkier
Novice


Joined: 28 Sep 2001
Posts: 45
Location: USA

PostPosted: Tue Jan 08, 2002 2:57 am   
 
Ok, I got the expand function to work here

First, I set this:
#VAR test ~@b

Then to show just the @b, use this:
#SHOW %expand(@test,1)

To explain, the 1 tells the expand function to expand the string @test once, which in turn is @b. If you changed it to 2, then it would also expand @b. If you changed it to -1, it would show @test.

I hope this helps you out.

Contain rather than hurt.
Hurt rather than maim.
Maim rather than kill.
Kill rather than be killed.
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Tue Jan 08, 2002 1:55 pm   
 
A quirk about this is that while
#SHOW %expand(@test, 1)

does display @B,
#EXEC %expand(@test, 1)

tries to expand @test and then @B isntead of sending @B to the MUD as expected. A quick work around for this is to use the %quote function like this:
#EXEC %quote(%expand(@test, 1)

which does send @B to the MUD.

Kjata
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