Variables linked in scripts

Posted by Shenlung on Tue 15 Nov 2005 01:03 PM — 4 posts, 16,816 views.

USA #0
I am trying to do something simple, I have absolutely *NO* prior knowledge of vbscript, so bear with me. I want to switch from single wield to a double wield in a series, but I cannot make the script hold the variables I set in the world.
here is the script in it's entirity... note that some of this is garbage, but I don't know which parts are and which aren't...tutorials anyone?

sub dualwield (name, line, wildcards)
  world.Send "relax grip"
dim weapon3

  weapon3 = world.GetVariable ("weapon3")

if isempty (weapon3) then
  world.note "My name is not defined"
end if

if isnull (weapon3) then
  world.note "Invalid variable name"
end if

world.note weapon3
  

  world.DoAfter 4, "Put @weapon3 in pack"
  world.DoAfter 6, "get @weaponl from pack"
  world.DoAfter 8, "get @weaponr from pack"
  world.DoAfter 10, "wield @weaponl left"
  world.DoAfter 14, "wield @weaponr right"
  world.DoAfter 17, "grip"
end sub

I got the world.doafter timers set right, but the variables just get slapped into the world "as is" I.E. @weaponl.

the world.note I put in to see if it got the variable, which is does, but then it doesn't apply it to the rest of the code.

-edit- typos suck
Amended on Tue 15 Nov 2005 01:05 PM by Shenlung
Australia Forum Administrator #1
You are confusing two techniques here. The @variable substitution is done in the "send" text, not in the script file. You also can omit "world." to save typing.

Here is one method of doing it:


sub dualwield (name, line, wildcards)
dim weapon3
dim weaponl
dim weaponr

  weapon3 = GetVariable ("weapon3")
  weaponl = GetVariable ("weaponl")
  weaponr = GetVariable ("weaponr")


  Send "relax grip"
  DoAfter 4, "Put " & weapon3 & " in pack"
  DoAfter 6, "get " & weaponl & " from pack"
  DoAfter 8, "get " & weaponr & " from pack"
  DoAfter 10, "wield " & weaponl & " left"
  DoAfter 14, "wield " & weaponr & " right"
  DoAfter 17, "grip"
end sub



You can also make it shorter by getting the variables as you need them:


sub dualwield (name, line, wildcards)

  Send "relax grip"
  DoAfter 4, "Put " & GetVariable ("weapon3") & " in pack"
  DoAfter 6, "get " & GetVariable ("weaponl") & " from pack"
  DoAfter 8, "get " & GetVariable ("weaponr") & " from pack"
  DoAfter 10, "wield " & GetVariable ("weaponl") & " left"
  DoAfter 14, "wield " & GetVariable ("weaponr") & " right"
  DoAfter 17, "grip"
end sub



However the simple approach, which lets you use the @weapon3 technique, is to simply do the whole thing inside the alias, with "send to script":


<aliases>
  <alias
   match="dualwield"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="100"
  >
  <send>  world.Send "relax grip"
  world.DoAfter 4, "Put @weapon3 in pack"
  world.DoAfter 6, "get @weaponl from pack"
  world.DoAfter 8, "get @weaponr from pack"
  world.DoAfter 10, "wield @weaponl left"
  world.DoAfter 14, "wield @weaponr right"
  world.DoAfter 17, "grip"
</send>
  </alias>
</aliases>

USA #2
Nick, you are a god, hands down. Those three sets just taught me more about scripting in visual basic than the past three days of tearing through help files has, I think I may be able to script everything I need now, thank you. One question though... when you ran the entire thing as an alias, the <send> command was used to send commands to a temporary script, correct? I may not have looked in th right place in the help file, because I never saw that particular part...
Australia Forum Administrator #3
Yes, read this, it explains that part:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6030

The "send to script" effectively lets you script "on the fly", however it is in the same script space as the main script file (so you can share variables, for instance).