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
➜ General
➜ Converting zMUD math to MUSH math
Converting zMUD math to MUSH math
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| WHD
(1 post) Bio
|
Date
| Thu 19 Nov 2009 11:16 PM (UTC) |
Message
| How would I go about converting this zMUD script sample to MUSH?
#ALIAS moss {#math moss {%1 *40};#show @moss}
The way this particular line works is you enter the amount of moss you want to price and it does the math. So if you entered "moss 5" it would output "200" in the output window.
I plan on converting a zMUD calculator script to MUSH, and there are 34 lines just like this one that would need to be converted, plus a line that would total the 34 results and another that would clear all the inputs (resetting all the price totals back to 0).
Thanks for your help!
| Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #1 on Thu 19 Nov 2009 11:52 PM (UTC) Amended on Thu 19 Nov 2009 11:53 PM (UTC) by Twisol
|
Message
| A literal translation would look like this (assuming Lua as the selected scripting language):
<aliases>
<alias
match="moss *"
enabled="y"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>SetVariable("moss", %1 * 40)
Note(GetVariable("moss"))</send>
</alias>
</aliases>
(This is in the XML format, just copy it and click the Paste button on the Aliases dialog to load it.)
A more 'native' translation might look like this, though:
<aliases>
<alias
match="moss *"
enabled="y"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>-- temporarily store the value as a local
local num = tonumber("%1")
if num then
-- moss is likely defined elsewhere as a global
moss = %1 * 40
Note(moss)
else
Note("Must be a number.")
end</send>
</alias>
</aliases>
Here I added some error checking, and used Lua variables rather than MUSHclient's variable storage, because MUSH variables can only contain strings, plus they're relatively more efficient. I could have used a regular expression for the alias and limited the capture to only numbers, too. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Blainer
(191 posts) Bio
|
Date
| Reply #2 on Fri 20 Nov 2009 01:24 AM (UTC) Amended on Fri 20 Nov 2009 01:29 AM (UTC) by Blainer
|
Message
| I'd do this and maybe store the prices for items in MUSH Variables.
This trigger is catching a line that has the price of moss on it and then storing it for later.
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="The price of moss is: *"
send_to="12"
sequence="100"
>
<send>
moss_price = tonumber("%1")
</send>
</trigger>
</triggers>
This alias is for moss. It uses the price stored in moss_price to work out the cost and display the info then store it for later.
<aliases>
<alias
match="moss *"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>
--make the table for the first time
if not totals then
totals = {}
end
--make sure we have the price
if not moss_price then
Note("no moss_price")
return
end
--do the math
quant = tonumber("%1")
moss_total = quant * moss_price
--add this item to the totals table
totals.moss = moss_total
--now print out our moss info
--make a nice formated output string
output_string = string.format("%i x moss at %i will cost %i", quant, moss_price, moss_total)
--print the formated string to the command window
Note(output_string)
</send>
</alias>
</aliases>
Now I can get the totals with this alias when ever I want.
<aliases>
<alias
match="totals"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>
--make a var to hold the total
total = 0
--loop the totals table adding it up
for key, value in pairs(totals) do
total = total + value
Note(key.." total: "..value) --print each total
end
Note("The total cost is: "..total)
</send>
</alias>
</aliases>
I'd then follow the info bellow and make a plugin for it all.
| 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.
14,267 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top