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
➜ Need help with a command I've forgotten.
|
Need help with a command I've forgotten.
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Fjodor
Sweden (13 posts) Bio
|
| Date
| Sun 15 Dec 2002 10:23 PM (UTC) |
| Message
| Ok, I need help with this one.
Yes it's . and NOT ,
I have one var that is, let's say 77.45
a other var is, let's say 45.30
now I use var1 - var2 = var3
77.45-45.30 = 32.15 (should be)
But instead var3 becomes 3215
Ok, so now I need to implement a . into var3
so var3 becomes 32.15 like I want it to.
How do I do that ?
| | Top |
|
| Posted by
| Shadowfyr
USA (1,792 posts) Bio
|
| Date
| Reply #1 on Mon 16 Dec 2002 12:31 AM (UTC) |
| Message
| ?? This is very strange.. But one thing, it is:
result = value1 - value2
I am amazed that var1 - var2 = var3 even works and it is a strange side effect you got.
However, if you still get the problem after puting things in the right order, then the reason is due to all variables being type variant. Somehow the script engine keeps track of what it 'thinks' the variables contain, but do to being unable to specify an exact type, it will sometimes guess and get things very wrong. So when it does screw up you can do something like:
var3 = CDbl(var1) - CDbl(var3)
which should force it to treat the contents as decimal values and not integers. | | Top |
|
| Posted by
| Fjodor
Sweden (13 posts) Bio
|
| Date
| Reply #2 on Mon 16 Dec 2002 08:53 AM (UTC) |
| Message
| Ok, this is how it is :
Trigger : *HP[*/*] SP[*/*] ST[*%] PP[*%] CF[*%] FF[*%]*
Script :
----------------------------------------------------
Sub HpCalc (strTriggerName, trig_line, arrWildCards)
Dim HP, SP, ST, PP
Dim HP2, SP2, ST2, PP2
HP = arrWildCards (2)
SP = arrWildCards (4)
ST = arrWildCards (6)
PP = arrWildCards (7)
HP2 = HP - World.GetVariable ("LastHP")
SP2 = SP - World.GetVariable ("LastSP")
ST2 = CDbl(ST) - CDbl(World.GetVariable ("LastST"))
PP2 = CDbl(PP) - CDbl(World.GetVariable ("LastPP"))
World.Note HP2&SP2&ST2&"%"&PP2&"%"
World.SetVariable "LastHP", HP
World.SetVariable "LastSP", SP
World.SetVariable "LastST", ST
World.SetVariable "LastPP", PP
World.SetVariable "LastFF", FF
End Sub
----------------------------------------------------
The output looks like this :
HP[325/325] SP[72/72] ST[100.00%] PP[100.00%] /*snip*
0 0 682% 1884%
I cut away the last part of the hp line in this note because it's not needed.
And I have some more code to add the space on the World.Note line but it's not important here either.
My problem is that I get 682 and 1884 as reported change and not 6.82 and 18.84 as I want it to look like.
| | Top |
|
| Posted by
| Meerclar
USA (733 posts) Bio
|
| Date
| Reply #3 on Mon 16 Dec 2002 12:35 PM (UTC) |
| Message
| | I see 2 potential causes for this actually. First there is the potential that the script isnt including the decimal when you get the variable info from the mud. Second is the potential that the output isn't being maintained in dbl format because the variables are being converted rather than declared as dbl. I rather suspect the first cause before the second but one never can tell. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | | Top |
|
| Posted by
| Fjodor
Sweden (13 posts) Bio
|
| Date
| Reply #4 on Mon 16 Dec 2002 09:20 PM (UTC) |
| Message
| Well, I know there is a command to withdraw a letter/number from any place in a string, just don't remember the command.
was something like :
var = <command> (string, nr)
that would take the nr letter/number from the string and add to var.
If you do it like this
var2 = "abcde"
var = <command> (var2, 3)
then var = c.
I'm not 100% sure you typed it like that but was something similar.
Anyone know ? | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #5 on Tue 17 Dec 2002 11:01 AM (UTC) |
| Message
|
Quote:
HP2 = HP - World.GetVariable ("LastHP")
MUSHclient variables are stored as strings, so I would say:
HP2 = HP - CDbl (World.GetVariable ("LastHP"))
As for extracting part of a string, in VB it is "instr" - there are examples in the exampscript.vbs file that ships with MUSHclient.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Fjodor
Sweden (13 posts) Bio
|
| Date
| Reply #6 on Tue 17 Dec 2002 12:10 PM (UTC) |
| Message
| I came up with an idea to solve it, silly easy one but still, I just devided the sum with 100 and problem solved :P
| | Top |
|
| Posted by
| Rhinoa
United Kingdom (37 posts) Bio
|
| Date
| Reply #7 on Tue 17 Dec 2002 05:04 PM (UTC) Amended on Fri 14 Mar 2003 08:59 AM (UTC) by Rhinoa
|
| Message
| It's FormatPercent.
ie.
MyPercent = FormatPercent(2/32) ' MyPercent = 6.25%
~Rhinoa~ | | 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,717 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top