TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Check for the existence of an alias

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion
View previous topic :: View next topic  
Author Message
apog



Joined: 23 Dec 2007
Posts: 5

PostPosted: Tue Dec 25, 2007 8:29 am    Post subject: Check for the existence of an alias Reply with quote

I've searched on the forum and through the help files, but I can't seem to find a way to tell if an alias is already defined / exists.

I saw there used to be an ifexists statement, but it doesn't appear to be there any more.

Thanks in advance.
Back to top
View user's profile Send private message
apog



Joined: 23 Dec 2007
Posts: 5

PostPosted: Tue Dec 25, 2007 12:54 pm    Post subject: Reply with quote

Well.. I made up a function to do this based on the "convert" script in the scripts forum.

Code:

#function {IsAliasDefined} {
        #unvar IsAliasDefined_var;
        #var IsAliasDefined_var {%0};
        #alias {%%1} {
                #var IsAliasDefined_var {%%1}
        } {8};
        %0;
        #unalias {%%1};
        #if {"$IsAliasDefined_var" == "%0"} {
                #var result 0
        } {
                #var result 1
        }
}


Where I have %%1, you had %%90 and stated that is should substitute out to be %0. However, using the #alias command, I saw it was actually creating an alias called %90. I assume the behavior changed since that script was written. I chose %%1 (which cancels out to be %1) because I already have an alias defined for %0 and I don't want to overwrite it.

Again, if there is an alternate/easier way to do this, then I'd be more than happy to know about it.

Also, is there a temporary way to turn off the variable/alias creation/destruction messages temporarily during the function. I tried #message variables off;#messages aliases off, then the opposite when the function is completing. However, then I just get the following spam (which isn't any better):

#OK: #VARIABLE MESSAGES HAVE BEEN SET TO: OFF.
#OK: #ALIAS MESSAGES HAVE BEEN SET TO: OFF.
#OK: #VARIABLE MESSAGES HAVE BEEN SET TO: ON.
#OK: #ALIAS MESSAGES HAVE BEEN SET TO: ON.

For those, I couldn't figure out which message class those messages were or how to turn them off.

EDIT:
Well, this works for functions that solely output to the mud (#alias {blah} {tell x blah}), but it executes the alias if it contains a "#" command (#alias {blah} {#showme {blah!}}). So this doesn't end up helping much. Though hopefully someone might be able to use it.

EDIT 2:
I grep'd through the source and definately couldn't find any "#" commands to do this. So I went ahead and created an "#exists" comand with the syntax "#exists {type} {name} {variable}" where type is alias or variable (those are the only ones I needed), name is the name of an alias/variable and "variable" is the variable that will get the value of 1 or 0 depending upon if the named alias/variable exists. I used the searchnode_list function as the backbone of the command. I'd just like to say that it was very easy with the framework you set up and thank you for all your hard work.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Wed Dec 26, 2007 3:54 pm    Post subject: Reply with quote

apog wrote:
Where I have %%1, you had %%90 and stated that is should substitute out to be %0. However, using the #alias command, I saw it was actually creating an alias called %90. I assume the behavior changed since that script was written.

It did, %0 to %99 are valid variables now.

apog wrote:

Also, is there a temporary way to turn off the variable/alias creation/destruction messages temporarily during the function. I tried #message variables off;#messages aliases off, then the opposite when the function is completing.

You should only be spammed if you provide the function as input, not when it's used in an action, alias, or macro.


apog wrote:

Well, this works for functions that solely output to the mud (#alias {blah} {tell x blah}), but it executes the alias if it contains a "#" command (#alias {blah} {#showme {blah!}}). So this doesn't end up helping much. Though hopefully someone might be able to use it.

It was an interesting approach, but indeed a bit messy. I'm opposed to adding a command to check whether an alias exists or not because I don't consider it necessary and don't want tintin to end up bloatware.


To check whether a variable exists you can use the following function:
Code:

#function {isvar}
{
    #if {"$%0" == "?%0"} {#var result 0} {#var result 1}
}
Back to top
View user's profile Send private message Send e-mail
andguent



Joined: 07 Jan 2011
Posts: 10

PostPosted: Fri Jan 11, 2013 7:15 am    Post subject: Reply with quote

If anyone searches for 'variable exists' or 'var exists' they may stumble onto this old thread.

As of 2.00.8 (and probably earlier) you can do a &variablename and get the #var position if it exists. It conveniently returns zero if the variable doesn't exist.

Code:

#var imreal yes
#var zero 0

#showme {imreal=$imreal}
#showme {zero=$zero}
#showme {imfake=$imfake}

#if {&imreal}{#showme Yup, its real}
#if {&zero}{#showme You're my zero}
#if {&imfake}{#showme This will not display}{#showme but this will}
Back to top
View user's profile Send private message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Fri Jan 11, 2013 8:12 pm    Post subject: Reply with quote

You may get some useful hints from this posting about whether a variable exists and what you can find out about it ...

apog wrote:
I used the searchnode_list function as the backbone of the command. I'd just like to say that it was very easy with the framework you set up and thank you for all your hard work.
Actually that sort of inspection function could be useful in some esoteric ways when you want do something in a script for instance cleaning up all the #DELAYs set up during a #PATH run which you need to abort midway because you've just run smack in to a load of enemies or you need to remove a load of ACTIONS before saving your script at the end of a session and you can't necessarily know in advance which ones will actually exist at that time.

Would you mind posting your code here?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> General Discussion All times are GMT - 5 Hours
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group