Author Topic: TrailMyx's CALL/GOSUB function handler  (Read 10871 times)

0 Members and 1 Guest are viewing this topic.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • 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
TrailMyx's CALL/GOSUB function handler
« on: September 18, 2008, 10:17:33 AM »
0
Ever want to:
  • Have a library of functions to call?
  • Be able to take library functions you have and use them as standard subroutines?

With this code snippet pasted to the top of your routines, you can convert any subroutine located under the snippet into one that can be "CALLED".

Code: [Select]
set !TM_FunctionCalled #FALSE
if %0 = 1 && !TM_FunctionCalled = #FALSE
  gosub %1
if %0 = 2 && !TM_FunctionCalled = #FALSE
  gosub %1 %2
if %0 = 3 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3
if %0 = 4 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4
if %0 = 5 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4 %5
if %0 = 6 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4 %5 %6
if %0 = 7 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4 %5 %6 %7
if %0 = 8 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4 %5 %6 %7 %8
if %0 = 9 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4 %5 %6 %7 %8 %9
if %0 = 10 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10
if %0 = 11 && !TM_FunctionCalled = #FALSE
  gosub %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11
if %0 > 11
{
  display ok Too many arguments for "call", edit file.
  stop
}

; exit  ; include this line if you don't want to run the error checking.  NOT RECOMMENDED!  Add "set !TM_FunctionCalled #TRUE" to the end of your subs for full error-checking!
 
if !TM_FunctionCalled = #TRUE ; successfully called function.
  exit
if %0 = N/A
  display ok You may not run this script directly.
else
  display ok Function " , %1 , " not found.
stop
 
;---------------------------------------------------------------
; Put your code under this comment.
; Sample code below, not needed for you.
 
sub SampleSub
  ; your code....
  ;
  set !TM_FunctionCalled #TRUE ; add this line when you return from your subs to let the calling routine know the subroutine was found.
return

The only additional thing you need to do for each subroutine is add a:

Code: [Select]
  set !TM_FunctionCalled #TRUE

to the end of each function right before it returns to the invoking "gosub".  If you just want to have a drop-in way of doing this, just add an "exit" to the code snippet right after all the "gosubs".  Then no function call check will occur.  I don't recommend this because otherwise you won't really know if the function was ever called and this can be hard to debug.

I had posted this at EasyUO today, but I remember I never posted this snippet here.  So here you go!

TM

« Last Edit: September 18, 2008, 10:19:32 AM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Khameleon

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2574
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +238
  • Referrals: 0
    • View Profile
Re: TrailMyx's CALL/GOSUB function handler
« Reply #1 on: September 18, 2008, 02:06:29 PM »
0
Your take on Alexandria?

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • 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: TrailMyx's CALL/GOSUB function handler
« Reply #2 on: September 18, 2008, 03:01:21 PM »
0
I've always liked it.  The staff is kinda grumpy (aside from Snicker7) but they do a good job and have some pretty original ideas.  S7 took me on a tour one evening and showed me all kinds of custom things they can do.  Pretty amazing stuff.  The custom dungeons that Nilmer has worked on are diabolical.

It's really too bad the population is as small as it is.  Frankly, I personally like it that way, but I'm a minority for sure in that regard.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Khameleon

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2574
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +238
  • Referrals: 0
    • View Profile
Re: TrailMyx's CALL/GOSUB function handler
« Reply #3 on: September 18, 2008, 03:15:11 PM »
0
I ment the old Subs program :P
Code Name Alexandria
http://www.easyuo.com/forum/viewforum.php?f=12
it was a library of subs that where used all the time.
the only problem was it relayed on contkinds.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • 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: TrailMyx's CALL/GOSUB function handler
« Reply #4 on: September 18, 2008, 03:21:14 PM »
0
I ment the old Subs program :P
Code Name Alexandria
http://www.easyuo.com/forum/viewforum.php?f=12
it was a library of subs that where used all the time.
the only problem was it relayed on contkinds.


Ohh, those.  Dunno.  I looked at them early on, didn't like what I saw and proceeded to code my own..  ;)

I thought you were just derailing another thread!  heh
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline VicVega

  • Jr. Member
  • **
  • Posts: 71
  • Activity:
    0%
  • Reputation Power: 0
  • VicVega has no influence.
  • Respect: +8
  • Referrals: 0
    • View Profile
Re: TrailMyx's CALL/GOSUB function handler
« Reply #5 on: April 19, 2009, 08:04:06 AM »
0
The problem calling subs from a text file it's that you can't execute the program line by line, so in this way debug problems it's harder.

How do you manage with that?

Also, why not make this set right after each sub?

Code: [Select]
sub SampleSub
  ; your code....
  ;
  set !TM_FunctionCalled #TRUE ; add this line when you return from your subs to let the calling routine know the subroutine was found.
return

In case you have a code like this:

Code: [Select]
sub SampleSub
set !TM_FunctionCalled #TRUE
if something
return #false
else
return #true
return
« Last Edit: April 19, 2009, 08:46:39 AM by VicVega »
To learn, read.
To know, write.
To master, teach.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • 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: TrailMyx's CALL/GOSUB function handler
« Reply #6 on: April 19, 2009, 09:22:24 AM »
0
In the older version of EUO, you could actualy step through even called subroutines.  Then it got broken when they went to 1.5 and never got fixed.

The !TM_FunctionCalled variable is there to let the call handler know if you have actually run the routine you were intending to. 

If you look at the bottom of the call handler code, you'll see this:

Code: [Select]
if !TM_FunctionCalled = #TRUE ; successfully called function.
  exit
if %0 = N/A
  display ok You may not run this script directly.
else
  display ok Function " , %1 , " not found.
stop

Suppose (using your example) you do this:

Code: [Select]
  call %mysubs SampleScub

Ordinarily you wouldn't know anything about your misspelled function name SampleSub.  But if you set the variable in your called sub, then you should get:

Quote
  Function SampleScub not found

At this point, I'm just sharing many many hours of frustrating debugging and my solution to save you countless hours determining that in fact you had a misspelling error and the routine you thought you were calling was never called.

Also, in your example, you can set the !TM_FunctionCalled value to #TRUE anywhere in your called routine as long as you set it inside the CALLING namespace.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline VicVega

  • Jr. Member
  • **
  • Posts: 71
  • Activity:
    0%
  • Reputation Power: 0
  • VicVega has no influence.
  • Respect: +8
  • Referrals: 0
    • View Profile
Re: TrailMyx's CALL/GOSUB function handler
« Reply #7 on: April 19, 2009, 09:51:18 AM »
0
Code: [Select]
sub SampleSub
set !TM_FunctionCalled #TRUE
if something
return #false
else
return #true
return

If instead of this I do this:

Code: [Select]
sub SampleSub
if something
return #false
else
return #true
set !TM_FunctionCalled #TRUE
return

Wouldn't that be a problem if returns with the "return #false"  line and never gets to the "set !TM_FunctionCalled #TRUE" line?
To learn, read.
To know, write.
To master, teach.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • 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: TrailMyx's CALL/GOSUB function handler
« Reply #8 on: April 19, 2009, 10:05:13 AM »
0
Yup, your logic flow has to take into account that the !TM_FunctionCalled must be set before you exit.  It's always going to be subject to how you code the individual subroutines so it's up to the interpretation of the individual programmer.
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: TrailMyx Snippet