ScriptUO
Official ScriptUO EasyUO Scripts => Script Debug => Topic started 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.
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
-
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.
-
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
-
I do it quite a bit as well, very handy in lengthy setup routines for example.
-
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)
-
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. ;)
-
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.
-
I do it with subs and Evil goto's. Works well