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

Return Statements & Braces

 
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: Sat Feb 22, 2014 11:26 am    Post subject: Return Statements & Braces Reply with quote

When using the #return statement in a function, the content is returned with the enclosing braces, as well as a pair of extraneous braces after the output.
The manual page on #return specifically shows that the content should be contained within braces:

Quote:
Syntax: #return {text}
space
The return command can be used to break out of a trigger that is being executed.
space
In a #function you can use #return with an argument to both break out of the function and set the result variable.


Here's an example:
Code:
#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:
Quote:
* 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.}{}


However, if I remove the braces from the #return statement:

Code:
#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}};


I get the expected output:
Quote:
* 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: Sat Feb 22, 2014 11:33 pm    Post subject: Reply with quote

Little oversight, fixed in the beta:

http://tintin.sf.net/download/tintin-beta.tar.gz
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