Gammon Forum
Entire forum
MUSHclient
General
add to variable
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| Kurapiira
(25 posts) bio
|
Date
| Fri 30 Apr 2010 05:32 AM (UTC) |
Message
| sorry...
folks on my mud use Mush because it is free.
they want to figure percentages.
Trying to do this..
swings at you...(add one to swings variable)
you parry...(add one to parry variable)
..and eventually...
ttl swings...ttl parry...ttl percent of parries
and a way to clear both variables.
Thanx for any ideas,
Kura | top |
|
Posted by
| Daniel P
USA (97 posts) bio
|
Date
| Reply #1 on Sat 01 May 2010 05:30 AM (UTC) Amended on Sat 01 May 2010 05:33 AM (UTC) by Daniel P
|
Message
| For starters take a look at the help files for GetVariable("name") and SetVariable("name",value).
Also note that you'll get errors if you try and add a blank variable to a number, so your clear script should initialise them to 0 rather than simply blank them out.
All you need do to set the addition of a variable to 1 is:
SetVariable("VarName",(GetVariable("VarName") + 1))
Then to display, you could use the Note() and GetVariable() functions:
Note("Parry: " .. GetVariable("parryTotal"))
Note("Swing: " .. GetVariable("swingTotal"))
And for your percentage, if I'm guessing right, you will:
Note("Percentage parried: " .. ((GetVariable("parryTotal")/GetVariable("swingTotal"))*100) .. "%")
Clearing is probably the easiest thing, as you will:
SetVariable("varName","0")
Hope that helps! | top |
|
Posted by
| Kurapiira
(25 posts) bio
|
Date
| Reply #2 on Tue 04 May 2010 06:03 AM (UTC) Amended on Tue 04 May 2010 06:28 AM (UTC) by Kurapiira
|
Message
| Many many thanks..this worked great...here is what i got..
__________________
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^The (.*?) attacks you with (.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable("Attacks",(GetVariable("Attacks") + 1))
Note("ttl-Attacks: " .. GetVariable("Attacks"))</send>
</trigger>
</triggers>
___________________
<triggers>
<trigger
enabled="y"
expand_variables="y"
match="^(.*?), but you parry the blow with your (.*?)$"
regexp="y"
send_to="12"
sequence="100"
>
<send>SetVariable("Parries",(GetVariable("Parries") + 1))
SetVariable("Attacks",(GetVariable("Attacks") + 1))
Note("ttl-Attacks: " .. GetVariable("Attacks"))
Note("Parries: " .. GetVariable("Parries"))
Note("Percentage parried: " .. ((GetVariable("parries")/GetVariable("Attacks"))*100) .. "%")</send>
</trigger>
</triggers>
____________________-
and aliases....sc (show counter) and zc..(zero counter)
<aliases>
<alias
match="sc"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>Note("Attacks: " .. GetVariable("Attacks"))
Note("Parries: " .. GetVariable("Parries"))
Note("Percentage parried: " .. ((GetVariable("parries")/GetVariable("Attacks"))*100) .. "%")</send>
</alias>
</aliases>
_______________-
<aliases>
<alias
match="zc"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>Note("Zeroing counters")
SetVariable("Attacks","0")
SetVariable("Parries","0")
Note("Attacks: " .. GetVariable("Attacks"))
Note("Parries: " .. GetVariable("Parries"))
</send>
</alias>
</aliases>
________________
Thanks again!...:)
K.
p.s. is there any way to limit the percent thyng to just
3 numbers...i.e. ...
12.53333333
to 12.5
thanx again!
| top |
|
Posted by
| Garrion
(21 posts) bio
|
Date
| Reply #3 on Tue 04 May 2010 08:13 AM (UTC) |
Message
| I would use the string.format function.
parry_text = string.format("%4.1f", GetVariable("parryTotal"))
Note("Parry: " .. parry_text)
This should show the variable to 1 decimal place. Not sure if it is the best way to do it but it should work.
Garrion. | top |
|
Posted by
| Larkin
(278 posts) bio
|
Date
| Reply #4 on Tue 04 May 2010 02:54 PM (UTC) |
Message
| GetVariable returns a string, so you should convert the result to a number before you do the math...
SetVariable("name", tonumber(GetVariable("name") or "0") + 1)
| top |
|
Posted by
| Daniel P
USA (97 posts) bio
|
Date
| Reply #5 on Wed 05 May 2010 05:39 PM (UTC) Amended on Wed 05 May 2010 05:40 PM (UTC) by Daniel P
|
Message
| In addition to string.format() you can also use math.floor() and math.ceil() which will round the number either up or down to the nearest integer.
Example in the help file is:
Note(math.floor(5.5))
-->5
Note(math.ceil(5.5))
-->6
But to get the decimal values, yes it is best to use string.format(). The help file on that will have a few examples which should explain all the options. | top |
|
Posted by
| Nick Gammon
Australia (22,973 posts) bio
Forum Administrator |
Date
| Reply #6 on Wed 05 May 2010 08:57 PM (UTC) |
Message
|
Daniel Powell said:
In addition to string.format() you can also use math.floor() and math.ceil() which will round the number either up or down to the nearest integer.
Also see commas.lua.
There is a "round" function in that which actually rounds (math.floor and math.ceil truncate up or down, whereas round goes up or down depending on which integer it is closer to). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | 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,303 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.