Author Topic: Variable Subs....what does everyone think of this?  (Read 1927 times)

0 Members and 1 Guest are viewing this topic.

Offline XclioTopic starter

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Variable Subs....what does everyone think of this?
« on: July 01, 2009, 05:30:34 AM »
0
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

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13107
  • Activity:
    1.8%
  • Reputation Power: 152
  • 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: +1339
  • Referrals: 32
    • View Profile
    • ScriptUO
Re: Variable Subs....what does everyone think of this?
« Reply #1 on: July 01, 2009, 05:36:34 AM »
0
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. 
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Variable Subs....what does everyone think of this?
« Reply #2 on: July 01, 2009, 05:37:47 AM »
0
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
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3617
  • Activity:
    0%
  • Reputation Power: 39
  • 12TimesOver has a powerful will.12TimesOver has a powerful will.12TimesOver has a powerful will.12TimesOver has a powerful will.12TimesOver has a powerful will.12TimesOver has a powerful will.12TimesOver has a powerful will.
  • Gender: Male
  • Respect: +316
  • Referrals: 2
    • View Profile
Re: Variable Subs....what does everyone think of this?
« Reply #3 on: July 01, 2009, 05:56:32 AM »
0
I do it quite a bit as well, very handy in lengthy setup routines for example.

When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline XclioTopic starter

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Re: Variable Subs....what does everyone think of this?
« Reply #4 on: July 01, 2009, 06:07:12 AM »
0
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)

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13107
  • Activity:
    1.8%
  • Reputation Power: 152
  • 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: +1339
  • Referrals: 32
    • View Profile
    • ScriptUO
Re: Variable Subs....what does everyone think of this?
« Reply #5 on: July 01, 2009, 06:10:54 AM »
0
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.  ;)
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline XclioTopic starter

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Re: Variable Subs....what does everyone think of this?
« Reply #6 on: July 01, 2009, 06:12:25 AM »
0
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.

Offline Superslayer

  • Elite
  • *
  • *
  • Posts: 1006
  • Activity:
    0%
  • Reputation Power: 14
  • Superslayer barely matters.Superslayer barely matters.
  • Gender: Male
  • Well what do you drink? Not tea.
  • Respect: +43
  • Referrals: 0
    • View Profile
Re: Variable Subs....what does everyone think of this?
« Reply #7 on: July 01, 2009, 12:20:16 PM »
0
I do it with subs and Evil goto's. Works well

Tags: