[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Converting zMUD math to MUSH math
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Converting zMUD math to MUSH math

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


Posted by WHD   (1 post)  [Biography] 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!
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] 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
[Go to top] top

Posted by Blainer   (191 posts)  [Biography] 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.
Template:post=9617 Please see the forum thread: http://gammon.com.au/forum/?id=9617.
[Go to top] 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.


3,567 views.

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

Go to topic:           Search the forum


[Go to top] 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.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]