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

Testing Variable Existence & Else Conditions

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
atraeyu



Joined: 12 Dec 2007
Posts: 165

PostPosted: Thu Feb 20, 2014 9:51 pm    Post subject: Testing Variable Existence & Else Conditions Reply with quote

When testing for variable existence, else conditions are not executed. The first four checks are relevant for this potential bug.

Script source: https://github.com/nfarrar/TinMan/blob/master/reference/variables/check-exists.tin

Code:

#nop ./reference/variables/check-exists.tin;
/*

    Some variable and argument existence tests to ensure they work as expected.

    It appears there is a bug in TinTin 2.01 where else clauses
    will not trigger when used with variable existence tests.

    It appears that you cannot test for argument existence in aliases and
    functions in TinTin 2.01.

    RUNME: tt++ reference/variables/check-exists.tin;
*/

#if {&{MOD_LOADED}} {
    #showme {! Module has previously been loaded.  Reinitializing environment.\n};
    #class {$MOD_NAME} {kill};
};

#if {!&{MOD_LOADED}} {
    #showme {! Module has not previously been loaded.  Initializing environment.\n};
    #var {MOD_NAME} {check-exists};
    #var {MOD_PATH} {reference/variables/check-exists.tin};
    #var {MOD_LOADED} {true};
};

#nop Kill the class code and reload this file.;
#alias {reload} {
    #sys {clear};
    #read {$MOD_PATH};
};

#class {$MOD_NAME} {open};
#config {VERBOSE} {ON};
#nop +-----------------------------------------------------------------------+;
#nop |                          Start of Class                               |;
#nop +-----------------------------------------------------------------------+;

#nop Set the test variable.;
#var {this_variable_exists} {true};

#nop We'll perform checks against the variable $this_variable_does_not_exist;
#nop which has not been set and does not exist when checking for a lack of;
#nop variable existence.;

#showme {* Testing the existence of $$this_variable_exists.};
#showme {* The message is generated by the #if clause.};
#showme {* We should see a message that the variable exists.};

#if {&{this_variable_exists}} {
    #showme {> This variable exists.};
};
#else {
    #showme {> This variable does not exist.};
};

/*
    Output from this test is as expected.
*/

#showme {\n* Testing the lack of existence of $$this_variable_exists.};
#showme {* The message is generated by the #else clause.};
#showme {* We should see a message that the variable does not exist.};

#if {!&{this_variable_exists}} {
    #showme {> This variable does not exist.};
};
#else {
    #showme {> This variable exists.};
};

/*
    Output from this test is not as expected.
    The #else clause does not execute.
*/

#showme {\n* Testing the lack of existence of $$this_variable_does_not_exist.};
#showme {* The message is generated by the #if clause.};
#showme {* We should see a message that the variable does not exist.};

#if {!&{this_variable_does_not_exist}} {
    #showme {> This variable does not exist.};
};
#else {
    #showme {> This variable exists.};
};

/*
    Output from this test is as expected.
*/

#showme {\n* Testing for the existence of $$this_variable_does_not_exist.};
#showme {* The message is generated by the #else clause.};
#showme {* We should see a message that the variable does not exist.};

#if {&{this_variable_does_not_exist}} {
    #showme {> Ths variable exists.};
};
#else {
    #showme {> The variable does not exist.};
};

/*
    Output from this test is not as expected.
    The #else clause does not execute.
*/

#showme {\n* Testing for the existence of %1 in an alias. We should see two messages.};
#showme {* The first message should be generated by the #if clause and say that %1 does not exist.};
#showme {* The second message should be generated by the #else clause and say that %1 exists.};

#alias {aArgExists} {
    #if {!&{%1}} {
        #showme {> The argument %%1 does not exist.};
    };
    #else {
        #showme {> The argument %%1 exists.};
    };
};

aArgExists;
aArgExists {arg1};

/*
    Output from this test is not as expected.
    In both cases the test for the existence of %1 fails and the #else clause executes.
*/

#showme {\n* Testing for the existence of %1 in a function. We should see two messages.};
#showme {* The first message should be generated by the #if clause and say that %1 does not exist.};
#showme {* The second message should be generated by the #else clause and say that %1 exists.};

#function {fArgExists} {
    #if {!&{%1}} {
        #return {> The argument %%1 does not exist.};
    };
    #else {
        #return {> The argument %%1 exists and is set to %1\.};
    };
};

#showme {@fArgExists{}};
#showme {@fArgExists{arg1}};

/*
    Output from this test is not as expected.
    In both cases the test for the existence of %1 fails and the #else clause executes.
    Additionally, the returned string contains extraneous braces. I am not sure why.
*/

#nop +-----------------------------------------------------------------------+;
#nop |                           End of Class                                |;
#nop +-----------------------------------------------------------------------+;
#config {VERBOSE} {OFF};
#class {$MOD_NAME} {close};




Output:
Code:

* Testing the existence of $this_variable_exists.
* The message is generated by the #if clause.
* We should see a message that the variable exists.
> This variable exists.

* Testing the lack of existence of $this_variable_exists.
* The message is generated by the #else clause.
* We should see a message that the variable does not exist.

* Testing the lack of existence of $this_variable_does_not_exist.
* The message is generated by the #if clause.
* We should see a message that the variable does not exist.
> This variable does not exist.

* Testing for the existence of $this_variable_does_not_exist.
* The message is generated by the #else clause.
* We should see a message that the variable does not exist.

* Testing for the existence of %1 in an alias. We should see two messages.
* The first message should be generated by the #if clause and say that %1 does not exist.
* The second message should be generated by the #else clause and say that %1 exists.
> The argument %1 does not exist.
> The argument %1 does not exist.

* Testing for the existence of %1 in a function. We should see two messages.
* The first message should be generated by the #if clause and say that %1 does not exist.
* The second message should be generated by the #else clause and say that %1 exists.
{> The argument %1 does not exist.}{}
{> The argument %1 does not exist.}{}
Back to top
View user's profile Send private message AIM Address
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3844

PostPosted: Fri Feb 21, 2014 9:09 pm    Post subject: Reply with quote

#else needs to be embedded within a trigger in order to work.

I can't treat a script file as a single code block because of backward compatibility issues.

One work around would be:

Code:

#1 {
#if {&{this_variable_does_not_exist}} {
    #showme {> Ths variable exists.};
};
#else {
    #showme {> The variable does not exist.};
}
}
Back to top
View user's profile Send private message Send e-mail
atraeyu



Joined: 12 Dec 2007
Posts: 165

PostPosted: Fri Feb 21, 2014 9:19 pm    Post subject: Reply with quote

Thank you. Smile

What is a trigger? I don't see it listed in the manual ....
Back to top
View user's profile Send private message AIM Address
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3844

PostPosted: Fri Feb 21, 2014 11:44 pm    Post subject: Reply with quote

A trigger is an alias, action, macro, delay, timer, or event.

Certain commands can contain a block of code as well.

A script file historically was a command file with each command separated by a new line.

I guess I could allow merging commands in a file if they're separated by a ; though in your example file this could result in a buffer overflow. So that would have to wait until I finish implementing infinite string support.
Back to top
View user's profile Send private message Send e-mail
atraeyu



Joined: 12 Dec 2007
Posts: 165

PostPosted: Sat Feb 22, 2014 10:58 am    Post subject: Reply with quote

Scandum wrote:
A trigger is an alias, action, macro, delay, timer, or event.

Certain commands can contain a block of code as well.

A script file historically was a command file with each command separated by a new line.

I guess I could allow merging commands in a file if they're separated by a ; though in your example file this could result in a buffer overflow. So that would have to wait until I finish implementing infinite string support.


What is this infinite string support I keep seeing you mention? Smile

Also, your statement about the commands being separated by a new line fills in a lot of gaps for me.

When I started writing tintin script files I noticed that if I had a nop statement follow immediately by another command the nop "consumed" the next command as a comment. However, if I added a semicolon to the end of the nop or a blank link after, this doesn't happen.

So - in terms of being safe, there should be a newline between each command (is this true inside codeblocks as well?) ...

Is there some syntax documentation somewhere that I missed that explains the syntax rules?
Back to top
View user's profile Send private message AIM Address
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3844

PostPosted: Sat Feb 22, 2014 11:27 pm    Post subject: Reply with quote

atraeyu wrote:

When I started writing tintin script files I noticed that if I had a nop statement follow immediately by another command the nop "consumed" the next command as a comment.

It does when embedded in a trigger or command, but not straight in a script file.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports 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