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 ➜ Insane Question

Insane Question

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


Posted by Microphone   (8 posts)  Bio
Date Sat 07 Feb 2004 06:22 AM (UTC)

Amended on Sat 07 Feb 2004 06:25 AM (UTC) by Microphone

Message
Okay, I have Name: level 1 experience 0 fp 6 hp 50 mp 25 strength 10 defense 7 speed 5 vitality 5 energy 5 stored as a variable, now, I made a script that will use fp on your other stats, but I have to get each individual stat so I made a sub to call in the sub UseFP, everything works so far, except it doesn't retrieve any values from the sub that's called. In the world.note that I made to show if it was retrieving the stats or not only shows the fp because I made that part of the script before I call the sub.. I have no idea what I did wrong or what to do, any answers?

The script is called on the trigger * whispers "use * fp on *" ignore case enabled

sub UseFP (name, output, wildcards)
name = wildcards(1)
fpnum = wildcards(2)
stat = wildcards(3)
a = world.getvariable(name)
b = instr(1, a, "fp")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 2+1, len(a)))
fp = left(d, instr(1, d, " "))


if len(a)=0 then
world.send "wh " + name + " You do not have an account!"
elseif instr(1, a, stat)=0 then
world.send "wh " + name + " That's not a stat."
elseif fp-fpnum < 0 then
world.send "wh " + name + " You do not have enough fp."
elseif lcase(stat)="hp" then
world.send "wh " + name + " You cannot use fp on that stat."
elseif lcase(stat)="mp" then
world.send "wh " + name + " You cannot use fp on that stat."
elseif lcase(stat)="experience" then
world.send "wh " + name + " You cannot use fp on that stat."
elseif lcase(stat)="fp" then
world.send "wh " + name + " You cannot use fp on that stat."
elseif lcase(stat)="level" then
world.send "wh " + name + " You cannot use fp on that stat."
else
call GetStats (name, output, wildcards)
world.note level + " " + experience + " " + fp + " " + hp + " " + mp + " " + strength + " " + defense + " " + speed + " " + vitality + " " + energy + "."

end if
end sub

sub GetStats (name, output, wildcards)

a = world.getvariable(name)
b = instr(1, a, "level")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 5+1, len(a)))
level = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "experience")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 10+1, len(a)))
experience = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "fp")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 2+1, len(a)))
fp = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "hp")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 2+1, len(a)))
hp = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "mp")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 2+1, len(a)))
mp = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "strength")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 8+1, len(a)))
strength = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "defense")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 7+1, len(a)))
defense = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "speed")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 5+1, len(a)))
speed = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "vitality")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 8+1, len(a)))
vitality = left(d, instr(1, d, " "))

a = world.getvariable(name)
b = instr(1, a, "energy")
c = mid(a, b, len(a)-b)
d = ltrim(mid(c, 6+1, len(a)))
energy = left(d, instr(1, d, " "))

end sub
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #1 on Sat 07 Feb 2004 06:08 PM (UTC)

Amended on Sat 07 Feb 2004 07:49 PM (UTC) by Shadowfyr

Message
Umm.. You are doing some really odd stuff here...

First:

sub UseFP (name, output, wildcards)
name = wildcards(1)

'name' starts as input from the trigger, then you redefine it as one of the wild cards. Not impossible, but also seriously not normal...

Then you do:

a = world.getvariable(name)

This won't work. It will attempt to retrieve a variable that is the same name as the contents of the 'name' variable, you need it to be ("name").

Later:

call GetStats (name, output, wildcards)

Why?? Triggers need to be called this way, your own subs do not. The only variable you appear to be using is 'name', so you could use:

call GetStats (name)

and define that sub as:

sub GetStarts (name)

Unless of course you also use this from a trigger, in which case your method would be correct. However, this isn't going to work as written anyway, since 'a' contains the stuff you want, not 'name'. You shouldn't use variables that have indistinct variables like that, it confuses things. Basically:

world.getvariable ("name") - This variable is not accessable or usable by the script. The script doesn't even know it exists. It is like a file on your hard drive and you must use getvariable and setvariable to save or retrieve values.

dim name, (name, output, wildcards) - These are script variables and only exists as long as the script runs. Like a document in word, until you save them permanently, they only survive until you end the sub. The exception being ones created globally, this last until the entire world closes.

You are incorrectly trying to pass to the second sub the permanent variable, which the script "can't" see directly, and instead end up passing the name of the person that wispered to you. This obviously won't work.

As for the rest..

You can use something like:

vals = split(a," ")
for count = 0 to ubound(vals) step 2
  if count = 0 then
    world.tell vals(count + 1)
  else
    world.tell " " & vals(count + 1)
  end if
next
world.note "."

This will work, since a split will create and array like:

vals(0) = "level"
vals(1) = 1
vals(2) = "experience"
vals(3) = 0
...

This way you can completely eliminate the second sub you call entirely. I do suggest coming up with *much* better variable names. The ones you are using confused me almost as much as they did you. lol This includes replacing the world.setvariable/world.getvariable one you are trying to use to something more sane, like "wrld_mystats". The 'wrld_' part isn't needed, but will help you remember that it is not a script variable and can't be tossed around the same way. ;)
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Sat 07 Feb 2004 08:45 PM (UTC)
Message
I got completely confused looking at that code. It is hard to see what you are doing, to say the least.

For one thing, why the trigger on a whisper? Are you doing it for yourself? Try using an alias.

Then all the instr, mid, ltrim and left has me confused. Can you post what is likely to be sent to the trigger? It seems unnecessary, what you are doing. And, if it *is* necessary, do it once in another function rather than dozens of times.

Next in GetStats you are doing:


a = world.getvariable(name)


about 10 times. Why? The variable isn't going to change, so doing it once will do.

I think you want something like this:


select case stat
  case "hp" hp = hp + 1
  case "defense" defense = defense + 1
  case "mana" mana = mana + 1
 ... and so on ...
end select


Even then I don't see what changing the variables will actually achieve. Do you mean to send something to the MUD?


- Nick Gammon

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

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #3 on Sun 08 Feb 2004 02:17 AM (UTC)
Message
Basically Nick, he is recieving some sort of whisper that tells him to do something. He is them checking that somehow to make sure he can, then later attempts to read his 'stored' stats from a mushclient variable and display them. The problem is he doesn't have the values global, is using confusing names, calling a sub that has a mess of redundant junk and generally making a royal mess of it.

His logic isn't entirely wrong, but he doesn't seem to understand the difference between local, global and mushclient variables, so nothing works as intended.
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #4 on Sun 08 Feb 2004 02:34 AM (UTC)

Amended on Sun 08 Feb 2004 02:36 AM (UTC) by Shadowfyr

Message
To give you a better idea what I mean Microphone... Think of it this way. Each 'sub' is like a seperate building. While different buildings may have baskets with similar name, someone in building #1 has no clue what is in building #2's boxes.

In your case, the 'level', 'experience' and other boxes are empty in the UseFP bulding, so you are sending a guy over to the GetStats building, where he sorts all the stuff into the right baskets. However, *and this is the important part*, he sorts them in to the baskets in the GetStats building, not UseFP. As a result, the guys over in UseFP still have a bunch of empty baskets, and no clue what the guy you sent over to GetStats actually did. Worse, once the guy left, the people in that building got annoyed with all the extra baskets lying around every place fed the contents of all your nice baskets through a shredder. lol You can't display what you don't have.

So.. extending this idea a bit more. These are the ways you can create variables:

Case #1:
dim myvar

sub yadda
...
end sub

Because the 'dim' above is *outside* of any sub or function, it becames a 'global'. Think of it like a guy hired to shove around a cart full of baskets and carry a pager. Whenever someone needs something from a basket, they page him and he runs to whatever building needs it.

Case #2:
sub yadda
  dim myvar
end sub

This *forces* the creation of a 'local'. This means that even if the guy with his pager and cart has something called 'myvar', the guys working in the building will look in *their* 'myvar' basket instead.

Case #3:
sub yadda
  myothervar = "Hello"
end sub

This *may* look just like case #1. The difference is that the guy with the cart has never seen a 'myothervar' basket and as far as he is concerned it isn't his job to worry about it. The result is identical to case #2. This is what you where using and since the cart guy didn't have it, there was no way it was going to get from one building to the other.

Case #4:
sub yadda (name, output, wildcards)
  world.note name
end sub


'name', 'output' and 'wildcards' are like access tubes. You send the information directly to the building, bypassing the cart guy. They belong *only* to the sub or function in which they are used, so are automatically 'local'. Changing them will have no effect on the contents of any global variables.

Case #5:
function yadda (type)
  if type = 1 then
    yadda = "Hello"
  end if
end function

sub stuff
  myyadda = yadda(1)
end sub

This is similar to case #2. However, the yadda building has a tube running *from* as well as into it. So they look over what you give them and stuff the result in the out tube to send back. In this case 'type' and 'myyadda' are both local. 'myyadda' is exactly like case #2, since no attempt was made to tell the cart guy to keep track of it.

Case #6:
setvariable ("myvar")

As I said before, this is a special case. Think of it as a vault, where you want to put stuff that you don't want going missing when the work shift ends and all your workers go home. Getting it back requires telling someone which basket in the vault to retrieve.

Your script didn't work, because instead of telling the guy from the vault to go get a basket labelled "name" from the vault, you sort of told him, "I think the basket I need is ..mumble mumble.. basket 'name' or something." So he did exactly what you told him to do, he looked into the 'name' basket on your desk and went looking for a basket in the vault based on what your 'name' basket had in it. In this case, he went looking for one labelled with the name of the guy that whispered the message to you. Of course, there wasn't any basket with that label in the vault.

Hope that makes sense and helps you understand scripting a bit better. ;)
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 08 Feb 2004 02:34 AM (UTC)
Message
Yes, I suppose.

He is passing down all his trigger stuff to the sub-function so I suppose there is some sense to that. However as you say he is setting up a lot of local variables that he does not then do anything with - even in the calling function. It is hard to see what they are for. Are they supposed to be sent somewhere, stored somewhere, or what?

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #6 on Sun 08 Feb 2004 02:39 AM (UTC)
Message
He uses a 'world.note' to display all the numbers from the mushclient variable:

world.note level + " " + experience + " " + fp + " " + hp + " " + mp + " " + strength + " " + defense + " " + speed + " " + vitality + " " + energy + "."

Right after the call to the other sub. But since those values are local to what he is calling, they never print. Also, he retrieve the mushclient variable incorrectly too, so it wouldn't work even if they where global.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #7 on Sun 08 Feb 2004 05:34 AM (UTC)
Message
Quote:

I made a script that will use fp on your other stats ...


Doesn't this mean he wants to do something with the "fp" other than simply do a world.note?

- Nick Gammon

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

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #8 on Sun 08 Feb 2004 07:50 PM (UTC)
Message
Probably. My guess is he got as far as what he showed, but nothing worked, so decided to ask what was wrong. But that is only a guess.
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,120 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.