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

Loopy behavior

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



Joined: 22 Mar 2008
Posts: 31

PostPosted: Wed Apr 02, 2008 7:08 pm    Post subject: Loopy behavior Reply with quote

If the arguments for the #loop command are wrong, tintin crashes instead of displaying an error message. I have several aliases that run loops and if I accidentally invoke one of the aliases without an argument, the loop chokes (eg. #loop {1 } {something}) Also, "#loop {1,2} {something}" causes a crash; it's the syntax in other mud clients and in older versions of tintin.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Thu Apr 03, 2008 9:06 am    Post subject: Reply with quote

It can freeze if you do that since #loop acts like a while loop with one argument. For example:

Code:

#var cnt 10

#loop {$cnt} {#showme $cnt;#math cnt $cnt - 1}
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Thu Apr 03, 2008 10:35 am    Post subject: Reply with quote

Scandum wrote:
It can freeze if you do that since #loop acts like a while loop with one argument.


Yup, I know. It'd be nice if, instead of freezing, the code checked that the first argument actually was a variable and displayed an error message when appropriate.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Thu Apr 03, 2008 11:53 am    Post subject: Reply with quote

I guess I could have the code check for a valid variable.

You can use #if {"%1" == "* *"} to check for a valid 2 number #loop however.
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Thu Apr 03, 2008 12:03 pm    Post subject: Reply with quote

Scandum wrote:
You can use #if {"%1" == "* *"} to check for a valid 2 number #loop however.


Can #if use regexps to check if the strings consist of digits?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Thu Apr 03, 2008 12:33 pm    Post subject: Reply with quote

Nope, but #regexp should be able to.
Back to top
View user's profile Send private message Send e-mail
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Thu Apr 03, 2008 5:09 pm    Post subject: Reply with quote

I just looked into it, but it'll be too much trouble checking for a valid variable given arguments like:

#loop {{$cnt > 0 && $bla}}

are valid as well.
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Fri Apr 04, 2008 10:25 am    Post subject: Reply with quote

So the single #loop command is being used for two distinct control-flow structures: a while loop and a for-next loop.

The original #loop command in tintin++ only supported the latter and reported "#Wrong number of arguments in #loop" when #loop was misused.

I created the thread because aliases like the following are fairly common:
Code:
#al {loot} {#loop {1 %1} {get all &0.corpse}}


"loot 5" works fine but if a user accidentally types only "loot", having the program crash or freeze is a severe result. Of course, the alias can have #if or #regexp to make sure the argument is proper but that ruins the simplicity of the original intent. Having aliases to look in n treasure chests or open n doors, etc. would necessitate that each alias checked the validity of their arguments. That's just unwieldy.

Besides, consider the semantics of a #loop command:

#loop {3} {#showme &0}
I'd expect that to loop once using the value 3, not create an infinite while loop.

If you compare the different flavors and versions of tintin (and other clients), the following syntax would make more sense than the current usage:

#loop {10, 5} {#showme &0}
(Loop from 10 to 5, decrementing by 1 with each pass. Aside from the ampersand, this syntax would be compatible with other tintins.)

#loop {1, 9, 2} {#showme &0}
(Loop from 1 to 9 with an increment of 2.)

#loop {1, 9, 0} {#showme &0}
(Display an error message because the increment is 0.)

#loop {3} {#showme &0}
(Execute the command only once, using the value 3.)

#loop {} {#showme &0}
(Do nothing or display a warning message.)

#loop {a, z} {#showme &0}
(Loop through the letters of the alphabet.)

#loop {fee fi fo fum} {#showme &0}
(Loop through the four strings "fee", "fi", "fo" and "fum".)

#loop {1 9} (#showme &0}
(note- no commas so loop through the two numbers and only those two numbers)

#loop {$listname} {#showme &0}
(Loop through the elements of listname.)

The last example would be ridiculously useful.


Of course, use a #while command to run a while loop. That removes the semantic ambiguity and allows the code to check the arguments of the #loop command.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Fri Apr 04, 2008 11:59 am    Post subject: Reply with quote

The following would be reasonably safe:

#al {loot} {#loop {1 0+%1} {get all &0.corpse}}

The , syntax was removed for consistency since braces and spaces are used to separate arguments, as in:

#al {loot} {#loop {{1} {0+%1}} {get all &0.corpse}}

Quote:

#loop {fee fi fo fum} {#showme &0}
(Loop through the four strings "fee", "fi", "fo" and "fum".)


This can be done with: #for {fee fi fo fum} {#showme &0}, also works with lists.

#parse {abcdefghijklmnopqrstuvwxyz} {#showme &0} would be the #loop {a z} equivalent.

I'm still pondering about using #while rather than #loop.

Also not too excited about the idea of increments since it can be dealt with by multiplying the loop results.
Back to top
View user's profile Send private message Send e-mail
Quackers



Joined: 22 Mar 2008
Posts: 31

PostPosted: Fri Apr 04, 2008 3:10 pm    Post subject: Reply with quote

Scandum wrote:
The following would be reasonably safe:

#al {loot} {#loop {1 0+%1} {get all &0.corpse}}


If the argument of loot isn't a number or is missing, then the loop will process 1 and 0, which could be bad. I'm relying on a #regexp command in every single loop alias I have. Both approaches are kludges, however. Having a separate #while command would allow the code to expect and check consistent syntax in #loop commands.

Quote:
The , syntax was removed for consistency since braces and spaces are used to separate arguments, as in:

#al {loot} {#loop {{1} {0+%1}} {get all &0.corpse}}


Yeah, but that could easily have been

#al {loot} {#loop {{1},{0+%1}} {get all &0.corpse}}


Quote:
This can be done with: #for {fee fi fo fum} {#showme &0}, also works with lists.


Aha. #forall isn't listed in the online manual.

Quote:
#parse {abcdefghijklmnopqrstuvwxyz} {#showme &0} would be the #loop {a z} equivalent.


That's also not in the online manual. I find it interesting that #parse was implemented directly when #loop and #format (and #regexp) could be used to construct a workaround to do the same thing. Wink

Quote:
Also not too excited about the idea of increments since it can be dealt with by multiplying the loop results.


It's a simple concept. #math would obfuscate commands, especially if the increment were the argument of an alias or were the result of a trigger.

I'd hate to #parse the alphabet in your previous example if, for some reason, I needed to skip an arbitrary n letters per iteration. And if the increment were -1, I'd have to define the parse string in reverse (or use an #if check to convert the string using an %r format).

Besides, as with almost everything else I'm posting, wouldn't tintin run faster by using built-in comand syntax rather than by parsing a scripted workaround?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Fri Apr 04, 2008 3:29 pm    Post subject: Reply with quote

I'll update the online manual sometime.

#help is the most accurate and up to date source of information.

You can use #loop {1 90} {#help &0} to view all help listings and dump them to file or something.


Parse was added to deal with strings, though I guess ideally one would use #run or #script when a more powerful/familiar scripting language is needed.

Quote:

Besides, as with almost everything else I'm posting, wouldn't tintin run faster by using built-in comand syntax rather than by parsing a scripted workaround?

As zugg has proven you don't have to actually have the fastest mud client in order to claim you do, so my answer would be no. Coffee

It'd certainly be faster, but the speed difference wouldn't be noticeable, everything under 50 micro seconds is instant after all.

You can use #info cpu to check if tintin is running smoothly I think.
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