ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: TaskForce on September 10, 2014, 01:29:06 AM

Title: Cascading subs
Post by: TaskForce on September 10, 2014, 01:29:06 AM
Hi,
I have written that long script a while ago, which consists of a lot of gotos depending from a hotkey and calls a sub, which itself calls other subs too.
Now goto has determined as "bad" especially if one tries to adapt the script to OpenEUO.

Code: [Select]
00:
gosub task N E S W 00 01 11 21 00
21:
gosub task N E E S 21 210 211 212 213
210:
gosub task E N S W 210 210 210 21 99
212:
gosub task N S E W 212 212 212 21 99
213:
gosub task N E W S 213 213 213 21 99
...
halt
main:

The sub task does something, the result is read by the operator on the screen and entered via hotkey to call the sub task again with different parameters.
Depending from the entered hotkey the sub would issue an goto %x, where x is the position of the parameter containing the next tag to goto.  My thinking now is, that it could be a way, to create simply subs instead of the tags and name them i.e. sub 21.

Code: [Select]
sub 21
gosub task N E E S 21 210 211 212 213
return

This however means, all subs would be started from within sub 00 and therefore create a hierarchy of cascaded, never really closed subs (unless the script comes to its planned halt within one of these subs).
The question now is: Is there a limit, how deep such cascade can be or a better idea to address the various parameter levels?

Greetings
TaskForce
Title: Re: Cascading subs
Post by: TrailMyx on September 10, 2014, 09:10:40 AM
The only limit is if you nest calls to gosub.  So if you recursively call a subroutine, there is a limit of 30 or 100 or something like that.  There is no limit on the gotos from what I know.

So are you just never returning from "task"?
Title: Re: Cascading subs
Post by: TaskForce on September 10, 2014, 02:25:31 PM
Thanks, that limit should be large enough.
If I want to avoid the gotos (which would be a requirement for OpenEUO adaption, although I find goto much more clean and with less lines) then yes, task calls itself again with a different parameter set using the appropriate sub.

Since the maximum number of recursions should not be over 4, this will be fine I think.

Greetings
TaskForce
Title: Re: Cascading subs
Post by: TrailMyx on September 10, 2014, 09:56:52 PM
The lack of goto plus some other constructs was what finally turned me off with Lua and OpenEUO.   Natively written stuff is fine, but EUO adaption is such a pain!
Title: Re: Cascading subs
Post by: Crome969 on September 11, 2014, 01:41:21 PM
The lack of goto plus some other constructs was what finally turned me off with Lua and OpenEUO.   Natively written stuff is fine, but EUO adaption is such a pain!
Cascading like this on a string interpreter would hurt me too much.
remembers me on Den who had cascading subs with nested anonymous parameters in order to hide the real code behind..

Thats the point were i love to compile my scripts and just obfuscate them instead of spending hours doing nestings on 100+ String Attributes. Away from talking of performance, did you actually checked this out?
Title: Re: Cascading subs
Post by: Boydon on September 22, 2014, 01:10:58 PM
Once upon a time, when EasyUO 1.4 ruled the world of scripting, there used to be the #subrec (http://www.easyuo.com/forum/viewtopic.php?f=19&t=4901) variable. Now, in EasyUO 1.5, this is not a variable anymore, so I guess there limitation has been lifted or the maximum number of allowed recursion is very high. :)