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

Posted by Dev on Fri 08 Sep 2006 06:54 PM — 8 posts, 26,360 views.

#0
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."
Australia Forum Administrator #1
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."

#2
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.
Australia Forum Administrator #3
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.
#4
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?
Australia Forum Administrator #5
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).
#6
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.
Australia Forum Administrator #7
There's your problem. Cint gives a 16-bit number. Change Cint to CLng.