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 ➜ Displaying a variable's contents in the output window. (mostly)

Displaying a variable's contents in the output window. (mostly)

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


Posted by MushclientNewbie   USA  (33 posts)  Bio
Date Sun 06 Jul 2003 03:51 AM (UTC)

Amended on Sun 06 Jul 2003 04:26 AM (UTC) by MushclientNewbie

Message
Here is the script that I am trying to use right now. It doesn't work and I'd like you guys to take a look at it. I've had some experience scripting in Unix, but this has got me boggled. I'll post the code and explain what I need it to do.. The parts that I've left un-commented are part of a rolling script. It checks the 'roll' (the wildcard) against a number (51 in this case) and decides if it supposed to roll or stop rolling. I've got that part worked out. Now, I'll explain the problems I do have with the code.

sub OnRoll (name, line, wildcards)
   dim roll
   dim max 'I'm unsure about this... This is the variable that I'm trying to initalize.
            Do I need to initalize it in some special way?
      roll = CInt (wildcards (1))
      max = 0 'Here is an uncertianty that I brought over from unix. I want the
               variable to be reset to keep other 'max roll' values from carrying
               over. I'm not entirely sure how to do it in vb, though. My first
               problem.
 if roll < 51 then
   world.send "roll"
 else
   world.EnableTrigger "LblRoll", 0
   world.Sound "***some wav sound***"
           end if
 if roll > max then 'Here is where I check the max.
      max = roll 'Here, I want the max to be set equal to the roll if the roll is
                  greater. Keeping a running record of the maximum roll. I don't
                  think that it works like the variable stuff in unix so this is
                  my second problem.
      world.note "Max roll =", max 'Here is the note to the world. I can get the text
                                   into the output all right, I just can't figure
                                   out how to 'print' the variable like in unix. My
                                   third problem.
    else
      world.note "Max roll =", max 'Here it prints if the max isn't beat.
           end if
end sub


I think that my code is sound.. I just don't know what syntax I need. Trust me when I tell you all that I've looked around. All I can find, though, are twenty page examples or every single function I don't need. Go ahead and reply as you like, but try to give me exact solutions to my three problem spots. If you want to send me to some basic vbScript site that has what I'm looking for, that would be great too. Thanks, Matt.
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 06 Jul 2003 04:37 AM (UTC)

Amended on Sun 06 Jul 2003 04:38 AM (UTC) by Nick Gammon

Message
Quote:

dim max 'I'm unsure about this... This is the variable that I'm trying to initalize.
Do I need to initalize it in some special way?



There are three ways you can maintain variables...


  1. Inside the sub - this will be initialised each time - I think - and won't be retained between calls. You don't need to explicitly declare it unless you have "option explicit" set.
  2. Outside the sub - this will retain its value between calls
  3. In a MUSHclient variable - this will retain its value between MUSHclient invocations (if you save the world file)


I suggest that if you are trying to remember the max roll the method you have chosen is the wrong one, especially if you are setting it to zero each time. I would at least put it outside the sub, and either initialise it statically, or have a trigger do it (eg. when it asks you your name).
eg.


dim max  ' declare outside a sub
max = 0  ' initialise it once

sub OnRoll (name, line, wildcards)
   
...

end sub


Quote:

max = 0 'Here is an uncertianty that I brought over from unix


Yes, that is how you set something to zero.

Quote:

max = roll


This is correct.

Quote:

world.note "Max roll =", max


You concatenate with "&", so do this:


world.note "Max roll = " & max







- Nick Gammon

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

Posted by MushclientNewbie   USA  (33 posts)  Bio
Date Reply #2 on Sun 06 Jul 2003 05:07 AM (UTC)

Amended on Sun 06 Jul 2003 05:46 AM (UTC) by MushclientNewbie

Message
Nick...

I love you! But, there is a problem with my code. When it runs, it just put the roll value into the max. Here's what I get:

Rolling stats for halfling ranger.:
Max: Str: 17  Int: 17  Wis: 21  Dex: 25  Con: 20
Cur: Str: 8   Int: 8   Wis: 8   Dex: 8   Con: 8 
[33] Cmds: help, end, roll, add, rem>  
roll
Max roll = 33

Rolling stats for halfling ranger.:
Max: Str: 17  Int: 17  Wis: 21  Dex: 25  Con: 20
Cur: Str: 8   Int: 8   Wis: 8   Dex: 8   Con: 8 
[27] Cmds: help, end, roll, add, rem>  
roll
Max roll = 27

Rolling stats for halfling ranger.:
Max: Str: 17  Int: 17  Wis: 21  Dex: 25  Con: 20
Cur: Str: 8   Int: 8   Wis: 8   Dex: 8   Con: 8 
[32] Cmds: help, end, roll, add, rem>  
roll
Max roll = 32


As far as I can tell, it should check to see if the variable in 'roll' is higher than the variable in 'max.' That's the second if statement. If it is higher, it should set the 'max' equal to the 'roll.' If it is lower, it should just print the max. Ugh, this is getting frustrating. I know this is simple stuff. The code I'm using is basically the same as what I've got in my first post. I just fixed it up a bit and added a subroutine that runs on a trigger when the mud connects, like you suggested. What am I missing?
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #3 on Mon 07 Jul 2003 01:09 AM (UTC)

Amended on Mon 07 Jul 2003 01:13 AM (UTC) by Magnum

Message
You set: max = 0 inside the subroutine. IE: Every single time you call the subroutine. Naturally, Max is always going to be lower than your roll.

To the fix the situation, put max = 0 outside the subroutine, probably immediately following the line where you Dim max, which should also be outside the subroutine. (You only want to clear it once per loading of MUSHclient).

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by MushclientNewbie   USA  (33 posts)  Bio
Date Reply #4 on Mon 07 Jul 2003 01:50 AM (UTC)
Message
I've taken care of that already. When the mud first connects I get a message about: "Abandon hope all ye who enter here..." I used that to trigger the dim max, max = 0 sub. There's something else wrong that I'm missing. Here's the complete 'script' file that I'm running right now. OnStart activates every time I connect and OnRoll activates every time the mud is commanded to roll.

sub OnStart (name, line, wildcards)
   dim max
   max = 0

world.note "Scripting enabled - script file processed"
End sub

sub OnRoll (name, line, wildcards)
   dim roll
      roll = CInt (wildcards (1))
 if roll < 51 then
   world.Send "roll"
    else
   world.EnableTrigger "LblRoll", 0
   world.Sound "C:\SIERRA\Half-Life\cstrike\sound\ambience\guit1.wav"
           end if
 if roll > max then
      max = roll
      world.note "Max roll = " & max
    else
      world.note "Max roll = " & max
           end if
End sub
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #5 on Mon 07 Jul 2003 03:00 AM (UTC)

Amended on Mon 07 Jul 2003 03:07 AM (UTC) by Magnum

Message
You are not grasping the scope of variables. Because you put the Dim statement inside a subroutine, it is only retained in memory while that particular subroutine is being executed.

Instead, you want the Dim statement outside ALL subroutines.

dim max
max = 0
world.note "Scripting enabled - script file processed"

sub OnRoll (name, line, wildcards)
   dim roll
      roll = CInt (wildcards (1))
 if roll < 51 then
   world.Send "roll"
    else
   world.EnableTrigger "LblRoll", 0
   world.Sound "C:\SIERRA\Half-Life\cstrike\sound\ambience\guit1.wav"
           end if
 if roll > max then
      max = roll
      world.note "Max roll = " & max
    else
      world.note "Max roll = " & max
           end if
End sub

Delete the trigger that fires on "Abandon hope all ye who enter here...", you don't need it. Any script outside of a subroutine will be executed immediately when you load the script, which happens when you load the World File, or forcefully reinitialize the script from the MUSHclient menu's.

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by Magnum   Canada  (580 posts)  Bio
Date Reply #6 on Mon 07 Jul 2003 03:14 AM (UTC)
Message
Actually, you could keep that other trigger and do this too:

   dim max
   max = 0

sub OnStart (name, line, wildcards)
   max = 0
   world.note "Scripting enabled - script file processed"
End sub

sub OnRoll (name, line, wildcards)
   dim roll
      roll = CInt (wildcards (1))
 if roll < 51 then
   world.Send "roll"
    else
   world.EnableTrigger "LblRoll", 0
   world.Sound "C:\SIERRA\Half-Life\cstrike\sound\ambience\guit1.wav"
           end if
 if roll > max then
      max = roll
      world.note "Max roll = " & max
    else
      world.note "Max roll = " & max
           end if
End sub

...which would initialize max to 0, both when you open the world, and when you see that line you mentioned. (in case you disconnect then reconnect without closing and re-opening the world).

Get my plugins here: http://www.magnumsworld.com/muds/

Constantly proving I don't know what I am doing...
Magnum.
Top

Posted by MushclientNewbie   USA  (33 posts)  Bio
Date Reply #7 on Mon 07 Jul 2003 03:18 AM (UTC)
Message
Thanks!
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.


24,808 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.