ScriptUO

Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Xclio on July 01, 2009, 05:30:34 AM

Title: Variable Subs....what does everyone think of this?
Post by: Xclio on July 01, 2009, 05:30:34 AM
Okay so I got this great idea last night to see if I could use a varible as a sub name...I could and it actually worked pretty nicely...so what does everyone think of doing this?  Below is the concept...this is not exact code I just wanted to give you all the idea of what I am talking about.

Code: [Select]
if %killmethod = 1
set %killsub magekill
if %killmethod  = 2
set %killsub meleekill
if %killmethod = 3
set %killsub mountkill
...
...
...
gosub %killsub
...
...
...
Sub magekill
....
....
....
Sub Meleekill
...
....
...
Sub Mountkill
Title: Re: Variable Subs....what does everyone think of this?
Post by: TrailMyx on July 01, 2009, 05:36:34 AM
Sure, I use that method all the time in my scripts.  Sometimes it makes debugging a pain because you don't have a set gosub, but it can simplify code. 
Title: Re: Variable Subs....what does everyone think of this?
Post by: Cerveza on July 01, 2009, 05:37:47 AM
It's a great concept... been done quite a bit though. You can also use attributes in the call....

set %killsub magekill
gosub %killsub YES NO SOMETIMES

sub magekill
set %1 cerveza_rocks ; yes
set %2 cerveza_sucks ; no
set %3 cerveza_rules ; sometimes
Title: Re: Variable Subs....what does everyone think of this?
Post by: 12TimesOver on July 01, 2009, 05:56:32 AM
I do it quite a bit as well, very handy in lengthy setup routines for example.

Title: Re: Variable Subs....what does everyone think of this?
Post by: Xclio on July 01, 2009, 06:07:12 AM
Okay cool, I just liked the idea and wanted to make sure that it didn't have any major buggy features.   ScriptUO threw out a few pissed off syntax warning but other than that I really liked it and I was able to clean out some code (I am reworking alot of my Taming script since I am getting back into taming again)
Title: Re: Variable Subs....what does everyone think of this?
Post by: TrailMyx on July 01, 2009, 06:10:54 AM
Well SUO kinda as to do that because the value is determined at run-time, so the only thing it can do is issue a warning just to be sure you haven't actually made a syntax error or mistyped something.  That's why it's a warning and not an error.  ;)
Title: Re: Variable Subs....what does everyone think of this?
Post by: Xclio on July 01, 2009, 06:12:25 AM
Oh I totally agree it should be there otherwise you would have to make all kinds of ridiculous exceptions and thus would end up missing a ton of problems. 

You gotta realize I was up till 5am playing around with some code and had to be into work by 8am...I am a bit sleepy lol.
Title: Re: Variable Subs....what does everyone think of this?
Post by: Superslayer on July 01, 2009, 12:20:16 PM
I do it with subs and Evil goto's. Works well