Problems With Scripting Variables

Posted by Rhinoa on Wed 19 Dec 2001 11:15 AM — 24 posts, 86,772 views.

United Kingdom #0
I need help with scripting Variables...
I want it so that when someone says something to me... it'll set alot of Variables containing "stats"
I know how to do that bit.. but I can't figure out the Wildcard to make me say something back to that player straight away...
Also, when they say something else to me, it'll say all of they're "stats"
I know it's a must use VBScripts thing..
I know it can be done, I've seen it done before...
I know it's something like...

Trigger: (player's name) says: Stats
Label: SendStats
Script: SendStats

Sub SendStats
stat = world.GetVariable ("(Player's name)_stat")
world.send "say (Player's name) stat"
end sub

or something along those lines...

Thanx in advance.
~Rhinoa~
Canada #1
Could you cut and paste directly from the MUD output, the lines that you would like to trigger on?

Also, label names and script function/subroutine names must be unique... So where you listed "Label:" and "Script:", the names must be different.

The trigger will automatically pass any wildcards that were accepted to the script subroutine. It's your job to program the script to handle the wildcards, and store them in variables if you would like.

If you gave us the exact output from the MUD, someone here would probably be willing to do it for you.

Try looking at the sample .vbs file that is included with MUSHclient. Look at the mushclient commands that can be used (at http://www.mushclient.com/functions.htm ), and if need be, search Microsoft's site for help with programming in VBS. That's how I learned!

...or, like I've said, post the exact output, and someone here will do it for you. :)
Denmark #2
That seems fairly simple

first type:

/world.addtrigger "PlayerStatReq", "* says 'STATS'", "", 1, -1, 0, "", "SendStats"


change this part above as you want > "* says 'STATS'"

then insert this into your VbScript file:

sub SendStats(strTriggerName, trig_line, arrWildCards)
  world.send "say " + arrWildCards(1) + " " + world.getvariable (arrWildCards(1) + "_stat")
end sub


This simple sub should do the job as you describe it
Amended on Thu 20 Dec 2001 02:20 PM by Storm Dragon
United Kingdom #3
Thanx.. that worked perfectly!
~Rhinoa~
United Kingdom #4
New problem...
People that aren't registered are saying stats, and getting blank variables...
I need some Scripting that stops this...
I've been experimenting, and have come up with this...

if isempty(arrWildCards (1) & "Name") then
world.send "say " & arrWildCards (1) & " ,you are not currently registered, please say [Join]to me and try again!"
end if

But, for some reason, it doesn't seem to work...

~Rhinoa~
Denmark #5
Simply instead of:
  world.send "say " + arrWildCards(1) + " " + world.getvariable (arrWildCards(1) + "_stat")

type:
 if world.getvariable(arrWildCards(1) + "_stat") then
  world.send "say " + arrWildCards(1) + " " + world.getvariable (arrWildCards(1) + "_stat")
 else
  world.send "say " & arrWildCards (1) & " ,you are not currently registered, please say [Join]to me and try again!"
 end if

I think it should work, I am not sure since I have no way of testing it right now.
United Kingdom #6
Thanx again!
Working perfectly...
~Rhinoa~
United Kingdom #7
Hi again! :)

Not exactly a problem... but I'd like to know how to count how many members I have using VBScript.. (Can't be bothered to count it in the variables) :)

For a change.. I have no idea how to even start this one...
and i don't know if it's even possible...

Hope you can help!

~Rhinoa~
Denmark #8
I believe the easiest way is another variable.
though first you have to go through the hard part
of counting every entry you already have.
then insert something in the lines of checking if a person
is already in the list of members and then add 1 to the variable if the person is new.

if world.getvariable(arrwildcards(1) & "_stat") then
  world.send "say Hey you, " & arrwildcards(1) & ", stop messing with me, you are already a member!"
else
  world.setvariable "StatTotalMembers", world.getvariable("StatTotalMembers") + 1
end if


Above is just an example, use or abuse at will :P

United Kingdom #9
Thanks! I can't test it just yet... but it makes alot of sense... and I'm sure it'll work!


~Rhinoa~
United Kingdom #10
New problem..

Some of my variables contain "(Empty)" because they won't be used until that player does certain things...

Now... when someone says "Blah blah slot 1"
It says back all the variables that contain the "(empty)" word... and I don't want it to..
How can I fix this?
I've been experimenting, and have come up with this..

if world.getvariable (arrWildCards (1) & "Slot1") = ("(Empty)") then
world.send "say " & arrWildCards (1) & ", You do not currently have anything in that slot"
else
world.send "say " & arrWildCards (1) & "" & world.getvariable (arrWildCards (1) & "slot1") & ""
end if


But.. of course.. if that worked, I wouldn't be putting it here...
Denmark #11
 if mid(lcase(world.getvariable(arrWildCards(1) & "Slot1")),1,7) = "(empty)" then
  world.send "say " & arrWildCards (1) & ", You do not currently have anything in that slot"
 else
  world.send "say " & arrWildCards (1) & "" & world.getvariable (arrWildCards (1) & "slot1") & ""
 end if


Hmm... it did look alright before too, but try the above instead
United Kingdom #12
Thanks! That works lovely! :)

New problem though...

I have Variables containing a "money" stat, and when the player gets enough money.. they can buy potions..

Now, the potions cost 100 each... so the player will say "Buy 5 potions" the potions will be added to the players stats, and the correct amount of money will be removed from the stats.

Now... how can I do this?

Like always, I've been experimenting, and have come up with this:

if world.getvariable (arrWildCards (1) & "Gold") < arrWildCards & (2) * 100 then world.send "say " & arrWildCards & (1) & ", You do not have enough Gold to purchase " & arrWildCards & (2) & " Potions!"
if world.getvariable (arrWildCards & (1) & "Gold")>= arrWildCards & (2) * 100 then world.send "say " & arrWildCards (1) & " " & arrWildCards & (2) & " Potions have been added to your account! " & arrWildCards & (2) * 100 & " Gold has been removed from your account!"


But like always, it doesn't work :)

~Rhinoa~
Denmark #13
Before:
if world.getvariable (arrWildCards (1) & "Gold") < arrWildCards & (2) * 100 then world.send "say " & arrWildCards & (1) & ", You do not have enough Gold to purchase " & arrWildCards & (2) & " Potions!"
if world.getvariable (arrWildCards & (1) & "Gold")>= arrWildCards & (2) * 100 then world.send "say " & arrWildCards (1) & " " & arrWildCards & (2) & " Potions have been added to your account! " & arrWildCards & (2) * 100 & " Gold has been removed from your account!" 


Wrong : arrWildCards & (1)

Right : arrWildcards(1)

you made those errors throughout most of the lines.

Now:
if world.getvariable (arrWildCards(1) & "Gold") < arrWildCards(2) * 100 then
  world.send "say " & arrWildCards(1) & ", You do not have enough Gold to purchase " & arrWildCards(2) & " Potions!" 
end if
if world.getvariable (arrWildCards(1) & "Gold") >= arrWildCards(2) * 100 then
  world.send "say " & arrWildCards(1) & " " & arrWildCards(2) & " Potions have been added to your account! " & arrWildCards(2) * 100 & " Gold has been removed from your account!" 
end if


Ok.. when writing your own code remember to make it look nice, I can understand it better if it is not cluttered up
split the lines, I know there is a character in VB to notify it to split a line in two, I cant remember it now though
United Kingdom #14
Thanx, that works nicely..

and sorry about the last code... I was in a rush and wasn't thinking about I was typing =(

~Rhinoa~
United Kingdom #15
Actually that didn't work.. and only seemed to work the first time I tried it =(

I've got it done now though, using the code you suggested..

sub CalculateBuyPokeBalls (strName, trig_line, arrWildCards)
if arrWildCards (2) * 100 > world.getvariable (arrWildCards (1) & "Gold") * 1 then
world.send "wh " & arrWildCards (1) & " You do not have enough Gold to purchase " & arrWildCards (2) & " Pokeballs!" 
end if
if arrWildCards (2) * 100 =< world.getvariable (arrWildCards (1) & "Gold") * 1 then
world.send "wh " & arrWildCards (1) & " " & arrWildCards(2) & " Pokeballs have been added to your account! " & arrWildCards (2) * 100 & " Gold has been removed from your account!" 
end if
end sub


The only thing missing was the * 1 with the Gold variable.. and the arrwildcards (1) and get variable needed to be switched. (Don't know why.. just seems to work that way)other then that, it all worked.

~Rhinoa~
Australia Forum Administrator #16
Quote:

I know there is a character in VB to notify it to split a line in two, I cant remember it now though


That character is the underscore (_). eg.


if arrWildCards (2) * 100 > _
world.getvariable (arrWildCards (1) & "Gold") * 1 then


United Kingdom #17
New problem...
People that have a space in they're name (eg. Storm Dragon) are joining.. and no variable is being created for them (Because you can have spaces in variables)

How can I fix this?

No idea how to even start this... :(

~Rhinoa~
Australia Forum Administrator #18
Replace the space in the variable name with an underscore, when storing it, and replace the underscore with a space if you need to get it back.
Denmark #19
*cough* *cough*

Well.... lets see..

public SDfinal

sub SpaceToUnderscore(Incomming)
 dim x
 'This sub should convert spaces into underscores *shiver*
 SDfinal = ""
 for x = 1 to len(Incomming)
  if mid(Incomming, x, 1) = " " then
   SDfinal = SDfinal & "_"
  else
   SDfinal = SDfinal & mid(Incomming, x, 1)
  end if
 next
end sub

sub testscript(TrigName, TrigLine, WildCards)
 call SpaceToUnderscore(WildCards(1))
 world.setvariable SDfinal, "100"
end sub


I hope you can see what this does, I'm too lazy to explain at the moment and too lazy to include too many remark lines
good luck

ah yes, and you can easilly invert it too
Amended on Thu 03 Jan 2002 09:35 PM by Storm Dragon
Australia Forum Administrator #20
I had in mind something a bit simpler, using "replace". :)

Try this:


/world.note replace ("Nick Gammon wrote MUSHclient", " ", "_")


So, just use "replace" when you store the variable name, eg.


world.setvariable replace (playername, " ", "_"), contents

Denmark #21
... Was not aware there was such a routine
*shrug* Well I only know the old basic stuff :P
and I have no manuals on VB either.. it is nice to learn new stuff :)
United Kingdom #22
Isn't there a simpler way of doing it (I have alot of variables)
Australia Forum Administrator #23
Well, that only applies to the player name. If you have to set a lot of them you could make a small sub that sets a player name to a value, eg.


sub setvalue (playername, newvalue)
  world.setvariable replace (playername, " ", "_"), newvalue
end sub


Then use that in place of the "setvariable" you currently do. You could do that with a global find-and-replace.