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


Joined: 10 Aug 2004
Posts: 20
Location: UK, Uganda

PostPosted: Tue Aug 10, 2004 10:55 pm   

Variable names with special chars
 
I've recently purchased ZMud as it's a great programme, in fact it's one of the only pieces of software I've bought over the web. I am a programmer by professsion and I find customising zMud and writing code for triggers very entertaining.

Despite being an overall excellent programme it does suffer from being a little slow, and is prone to crashing, hanging and producing address exceptions, I'm trying to make these problems more reproduceable to help in tracking down these problems. I have found that dynamic interaction with the dB is extremely slow and so it is often better to create local variable copies of important data that needs to be accessed regularly.

Small complaints aside, it is a great programme and well worth the money.


Now to my little question, I wanted to write a script that allows the setting of toggleable only variable on the mud.

Here is some example data from the mud:
Quote:
#->toggle brief
Brief OFF.
#->toggle brief
Brief ON.

#->toggle auto-map
Auto-mapping is now ON.
#->toggle auto-map
Auto-mapping is now OFF.


The most obvious problem is the lack of consistency in the MUD output. Another problem is the need to send multiple settings at a time (e.g. from a script). Finally I wanted to still be able to toggle values and I didn't wan't the triggers fireing unnecessarily. However the following solution worked great:

Code:
#CLASS {Toggle}
#ALIAS toggle {#VAR %1 %2;#IF (%2) {#ADDITEM Toggles %1};~toggle %1}
#VAR Toggles {}
#REGEX "ToggleTrigger" {^(.*) (ON|OFF?)\.} {#FORALL @Toggles {#IF (%pos( %i, %lower( %1))) {#IF (@{%i}!=%lower( %2)) {~toggle %i} {#DELITEM @Toggles %i}}}} "" {case}
#CLASS 0


This provides an alias called toggle, which adds a little functionality to the MUD toggle command. If you specify only one parameter (e.g. toggle brief) it works identically to the MUD toggle command, but also creates a variable 'brief' and sets it to the value returned by the MUD. If you specify a second parameter (e.g. toggle brief on) it will continue toggling until the parameter is set correctly.

By using the Toggles string list variable it ensures that it only parses triggers currently being used and it means that it can match the various outputs of the MUD.

This is all very fine until you try toggling a variable with a '-' in it, like 'auto-map' in the example above. In that case the trigger keeps firing and toggling. The reason is simple and lies in the trigger where it says '@{%i}'. The code correctly creates a variable 'auto-map', as can be seen using the #VAR auto-map command. However ZMud doesn't like @{auto-map}, which the above expands to. For instance:

Code:
#VAR auto-map on
#VAR auto-map

Sets auto-map to 'on' and displays 'on'

But,
Code:
#SHOW @{auto-map}

displays '-map'

Therefore the trigger tries to compare '-map' to the value rather than the value of the variable 'auto-map', it fails so it tries toggling again.

The crux... how do you address variables with '-' symbols in them?? I know that I could make the code more complex, to remove or substitute the '-' symbol, but I was hoping there would be a more elegant solution.

Thanks for you help.

Craig
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: Wed Aug 11, 2004 4:16 am   
 
There is no way to access @auto-map, so just go ahead and remove or replace the -.
_________________
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
thargy
Beginner


Joined: 10 Aug 2004
Posts: 20
Location: UK, Uganda

PostPosted: Wed Aug 11, 2004 11:46 am   
 
Thanks for the reply.

I am thinking that
Code:
@{auto-map}

is interpreted as
Code:
{@auto}-map


I don't know why this would be a good idea, really you would think the curly brackets would group the variable name correctly. I can't find any documentation on this 'feature', so can I request that this be added somewhere in the help files in future, if there's no plans to change it.

Thanks

Craig

Thanks
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Aug 11, 2004 9:46 pm   
 
The main bug involved here is that the dash is not considered a valid character within a variable name. The #VARIABLE command allows you to bypass this when it shouldn't. Please post a bug report regarding this to the bug tracking system.

You are quite right in that "@{auto-map}" is in fact interpretted as "@{auto}-map". This also is a bug as the first should be interpretted as an invalid variable name and return %null.

Please report both and reference this topic. Zugg will decide the final thing, and if he makes any notes about it then it will be added in the help.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
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