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
Altman
Beginner


Joined: 02 Feb 2010
Posts: 16

PostPosted: Sun Feb 07, 2010 1:00 pm   

How to execute a two word variable?
 
I am capturing a two word string from a location description. e.g. The Bridge into a variable called @location

I then want to have an alias called toThe Bridge which contains the script to walk from a set position to that location.

So I capture the location name and then #execute to@location

This produces toThe Bridge

but this will not run the alias. I'm assuming that it is because there is a space between the two words. So is there a way to either execute a two word alias or else to remove the space between the two words in the @location variable so that it stores TheBridge (I can then rename the alias and all will be well)?

Thanks in advance!
Reply with quote
shalimar
GURU


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

PostPosted: Sun Feb 07, 2010 1:57 pm   
 
%replace(@location, " ")
_________________
Discord: Shalimarwildcat
Reply with quote
Altman
Beginner


Joined: 02 Feb 2010
Posts: 16

PostPosted: Sun Feb 07, 2010 2:20 pm   
 
Easy when you know how....

You guys are great. Thanks again!
Reply with quote
Altman
Beginner


Joined: 02 Feb 2010
Posts: 16

PostPosted: Sun Feb 07, 2010 9:43 pm   
 
All working fine except....

When @location = Magellan Travelers' Lodge

#execute to%replace(@location, " ") returns MagellanTravelers 'Lodge which is wrong

#show to%replace(@location, " ") returns MagellanTravelers'Lodge which is correct


I assume that the apostrophe is causing a problem with the #execute command. Anyone have a workaround?

Thanks.
Reply with quote
hadar
Apprentice


Joined: 30 Aug 2009
Posts: 198
Location: my apt, in california

PostPosted: Sun Feb 07, 2010 10:27 pm   
 
its something with execute %replace(%replace(@location," "),"'",) you can use that to output MagellanTravelersLodge if you can use that insted of MagellanTravelers'Lodge
_________________
if you build it they will come, assuming that they have not already come to build it
Aardwolf Bootcamp
My youtube channel
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Feb 08, 2010 3:34 pm   
 
That's correct. Variable names cannot contain certain characters, such as spaces or quotation marks.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Mon Feb 08, 2010 8:16 pm   
 
No, Rahab, that's not correct. Variable/alias creation has absolutely zero restriction on naming convention. If you really wanted to, you could name your variable/alias as " " (all whitespace, no quotes). You can even refer to such "illegally"-named settings, but doing so might be insanely difficult or outright impossible.

For example, even though you can easily have a two-word variable you cannot assign values to it via the a=b syntax. Additionally, much of the parsing is based on whitespace, so if you wanted to refer to this two-word variable you'd have to surround the name with curly braces (@{variable name}). Still further, certain characters seem to outright prevent reference to a variable name containing them EVEN THOUGH the #VARIABLE command happily creates the variable! For example, check out these commands:

#VARIABLE ~"test 13
#VARIABLE ~"test 14
#VARIABLE ~"test 15

Instead of reassigning the 14 and 15 to the original "test variable, it creates brand-new variables. It is impossible to refer to these variables because of how CMud processes the " character.

Aliases are much the same way, except that the plain-text style of execution means that ANY printable character can easily serve as a variable name without too much extra hoop-jumping to execute its code:

#execute %alias(name of alias here)

All of this is much more complicated than @varname or aliasname, so in the interests of simplicity and reability we advocate for varname/aliasname and find different ways to do stuff.
_________________
EDIT: I didn't like my old signature
Reply with quote
Altman
Beginner


Joined: 02 Feb 2010
Posts: 16

PostPosted: Mon Feb 08, 2010 8:59 pm   
 
Thanks again guys.

%replace(%replace(@location," "),"'",)

That works for me :-)
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Feb 08, 2010 9:40 pm   
 
Yes, you're right Matt. What I should have said is that variable names in Cmud (and Zmud) were never supposed to include spaces and certain punctuation marks, the code has never supported it, and was never intended to. To avoid potential mistakes in parsing, you should only use alphanumeric characters in variable names. Using any punctuation marks in a variable name could cause problems.

The fact that the compiler does not complain about variables with these characters just means that it is not restricted by the code (which some would consider a bug). It is still restricted in practice.
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