Author Topic: Cascading subs  (Read 3240 times)

0 Members and 1 Guest are viewing this topic.

Offline TaskForceTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Activity:
    0%
  • Reputation Power: 1
  • TaskForce has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Cascading subs
« on: September 10, 2014, 01:29:06 AM »
0
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
« Last Edit: September 10, 2014, 01:31:43 AM by TaskForce »

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Cascading subs
« Reply #1 on: September 10, 2014, 09:10:40 AM »
0
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"?
« Last Edit: September 10, 2014, 09:12:40 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline TaskForceTopic starter

  • Jr. Member
  • **
  • Posts: 16
  • Activity:
    0%
  • Reputation Power: 1
  • TaskForce has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Cascading subs
« Reply #2 on: September 10, 2014, 02:25:31 PM »
0
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

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Cascading subs
« Reply #3 on: September 10, 2014, 09:56:52 PM »
0
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!
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Crome969

  • Elite
  • *
  • *
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: Cascading subs
« Reply #4 on: September 11, 2014, 01:41:21 PM »
0
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?

Offline Boydon

  • ScriptUO Beta Tester
  • **
  • *
  • Posts: 76
  • Activity:
    0%
  • Reputation Power: 3
  • Boydon has no influence.
  • Respect: +16
  • Referrals: 0
    • View Profile
Re: Cascading subs
« Reply #5 on: September 22, 2014, 01:10:58 PM »
0
Once upon a time, when EasyUO 1.4 ruled the world of scripting, there used to be the #subrec 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. :)
Member of the Stealth development team.

Tags: