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 ➜ Variable doesn't update fast enough (or Mush moves on too quickly)

Variable doesn't update fast enough (or Mush moves on too quickly)

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


Posted by Dev   (6 posts)  Bio
Date Fri 08 Sep 2006 06:54 PM (UTC)
Message
My variable "level" is set to 91. I want it to increase by 1 when I level, which it does. The problem is that the second line must already have the @level variable cached, because even though I look in my variable list and it says 92 when the script sends text to the mud it says 91. Any ideas?

world.setvariable "level", Cint(getvariable("level")) +1
world.send "gt Level @level: I gained %1 hp and %3 mana while receiving %7 practices."
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 08 Sep 2006 07:38 PM (UTC)
Message
Variable substitutions are done before the script is called, so the second line will have the old value. You need to do this:


SetVariable "level", Cint(GetVariable("level")) +1
Send "gt Level " & GetVariable("level") & _
     ": I gained %1 hp and %3 mana while receiving %7 practices."


- Nick Gammon

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

Posted by Dev   (6 posts)  Bio
Date Reply #2 on Sat 09 Sep 2006 12:24 AM (UTC)
Message
On a somewhat (variable) related note, I'm having a problem with my damage counter. I can set it up to work fine, but once it reaches a certain number (around 32000) it doesn't do anything and pops up with error messages that make it impossible for me to play without closing them every time I hit the enemy.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 09 Sep 2006 12:33 AM (UTC)
Message
If you have version 3.79 onwards of MUSHclient there is a checkbox in the scripts configuration "Note errors". If you check that, then errors just appear in the output window and do not open an annoying dialog box.

If the variable wraps around at about 32000 it sounds like a 16-bit number (max 32767). Try making it longer, with a floating point number of a "long".

In VBscript CLng converts to a long, which is 32 bits.

- Nick Gammon

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

Posted by Dev   (6 posts)  Bio
Date Reply #4 on Mon 11 Sep 2006 12:14 AM (UTC)
Message
Do I have to do that every time? Originally I created the variable using the variable list in Mush, is there a way to change that way that one is handled, as it seems this one is only for internal vbscript variables?
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Mon 11 Sep 2006 01:41 AM (UTC)
Message
The variable list is strings only. You must be converting it to a number to add things to it. Can you show how you are doing that?

For example, if "counter" variable is 5, then if you do this:

x = GetVariable ("counter")

You really get "5" and not 5.

If you try this:

/Note (VarType (x))

You should see a number.

The meaning of the numbers are:

  • vbEmpty 0 Empty (uninitialized)
  • vbNull 1 Null (no valid data)
  • vbInteger 2 Integer
  • vbLong 3 Long integer
  • vbSingle 4 Single-precision floating-point number
  • vbDouble 5 Double-precision floating-point number
  • vbCurrency 6 Currency
  • vbDate 7 Date
  • vbString 8 String
  • vbObject 9 Automation object
  • vbError 10 Error
  • vbBoolean 11 Boolean
  • vbVariant 12 Variant (used only with arrays of Variants)
  • vbDataObject 13 A data-access object
  • vbByte 17 Byte
  • vbArray 8192 Array


So, if your variables is type 2, it is a 16-bit integer. You want something like long (3) or double (5).

- Nick Gammon

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

Posted by Dev   (6 posts)  Bio
Date Reply #6 on Mon 11 Sep 2006 03:57 AM (UTC)
Message
the action I perform is

world.setvariable "damage", Cint(getvariable("damage")) + %2

where damage is the variable with the old damage, and %2 is the value for the damage I just dealt.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #7 on Mon 11 Sep 2006 04:13 AM (UTC)
Message
There's your problem. Cint gives a 16-bit number. Change Cint to CLng.

- 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.


25,086 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.