[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  Variables linked in scripts

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Variables linked in scripts

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Shenlung   USA  (2 posts)  [Biography] bio
Date Tue 15 Nov 2005 01:03 PM (UTC)  quote  ]

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-
[Go to top] top

Posted by Nick Gammon   Australia  (18,801 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 15 Nov 2005 07:02 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Shenlung   USA  (2 posts)  [Biography] bio
Date Reply #2 on Tue 15 Nov 2005 08:21 PM (UTC)  quote  ]
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-
[Go to top] top

Posted by Nick Gammon   Australia  (18,801 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 15 Nov 2005 08:29 PM (UTC)  quote  ]
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
[Go to top] 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.


1,205 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]