Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Variables linked in scripts

Variables linked in scripts

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Shenlung   USA  (2 posts)  Bio
Date Tue 15 Nov 2005 01:03 PM (UTC)

Amended on Tue 15 Nov 2005 01:05 PM (UTC) by Shenlung

Message
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

"Gentle people sleep sound in their beds, because there are hard men out in the night, willing to cause harm to those who would harm us" -Unknown-
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 15 Nov 2005 07:02 PM (UTC)
Message
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>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shenlung   USA  (2 posts)  Bio
Date Reply #2 on Tue 15 Nov 2005 08:21 PM (UTC)
Message
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...

"Gentle people sleep sound in their beds, because there are hard men out in the night, willing to cause harm to those who would harm us" -Unknown-
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 15 Nov 2005 08:29 PM (UTC)
Message
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).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


16,284 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.