[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]  Lua
. . -> [Subject]  A Little-More-Than-Simple Arithmetic Script
Home  |  Users  |  Search  |  FAQ
Register forum user name
Forgotten password?

A Little-More-Than-Simple Arithmetic Script

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Posted by Henry Tanner   Finland  (23 posts)  [Biography] bio
Date Mon 24 Aug 2009 04:41 PM (UTC)  quote  ]

Amended on Mon 24 Aug 2009 04:48 PM (UTC) by Henry Tanner

Hello folks.

I have struggled with a script that I am working on for a few hours now. I've spent most of the time wading back and forth in the vast sea of help files and the forums. Without finding (or understanding, [I admit that I'm not the sharpest tool in the box]) the information I need, I finally cracked and decided to ask for help in the form of this new post.

The MUD I am making this script for is called "Legends of the Jedi" and is a heavily modified SWR. In the MUD it is possible to purchase a freighter ship to transport varying resources from planet to planet and thus earn credits.

In the MUD there is a command "showplanet <planet> resources" that shows the current rates of the 0 to 10 different resources available on the planet like this:

You use the datapad to lookup the information.
--Planet Data: -------------------------------
Planet: Coruscant
Starsystem: Coruscant
Governed By: The New Republic
Planet Funds: 25000

Electronics ( Price per unit: 11.38)
Food ( Price per unit: 7.91 )
Goods ( Price per unit: 1.94 )
Lumber ( Price per unit: 9.22 )
Precious metals ( Price per unit: 1.79 )
Spice ( Price per unit: 1.09 )
Water ( Price per unit: 10.51)
Weapons ( Price per unit: 11.54)

I have created an alias "reso *" to do the command above.

The purpose of this script is to calculate the difference between the resource prices of two different planets and print it on the output. The script is pasted below and is executed by the alias "cargoroute * to *".

SetVariable ("cargo_from", "%1");
SetVariable ("cargo_to", "%2");

AddTriggerEx ("Cargo_A", "*          ( Price per unit: *)", "SetVariable ("Resource_%1_from", "%2")", "1", "-1", "0", "", "", "12", "100");
Execute ("reso "%1"");
DeleteTrigger ("Cargo_A");

AddTriggerEx ("Cargo_B", "*          ( Price per unit: *)", "SetVariable ("Resource_%1_to", "%2")", "1", "-1", "0", "", "", "12", "100");
Execute ("reso "%2"");
DeleteTrigger ("Cargo_B");

Resource_Electronics_to = tonumber (GetVariable ("Resource_Electronics_To"));

Resource_Electronics_from = tonumber (GetVariable ("Resource_Electronics_from"));
Electronics_difference = Resource_Electronics_to - Resource_Electronics_from;
Note "Electronics Rate: $Electronics_difference$";

The problem that I am currently facing is:

The AddVariable function that is "inside" the AddTrigger (on line 4) picks up "coruscant" from the alias that executes the script, instead of the %1 passing in to the trigger it creates.

The error message that MushClient gives me is:

Compile error
World: Legends of the Jedi
Immediate execution
[string "Alias: "]:4: ')' expected near 'Resource_coruscant_from'

I'll be very thankful if you can give me any kind of advice on this problem, also I would be very happy to have a somekind of a mentor on my buddy list on either AIM or MSN that I could have quick tips from since I feel very hesitant on posting on the forums (I don't want to be a nuisance).


I got this!
[Go to top] top

Posted by Nick Gammon   Australia  (19,670 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Mon 24 Aug 2009 08:54 PM (UTC)  quote  ]
Asking questions is no shame, we are here to help. :)

Personally I wouldn't be adding triggers all the time, unless absolutely necessary. Triggers can expand variables in the "match" text, so you should be able to make a couple of standard ones that you just use when you need them.

If I understand your problem correctly, "Resource_%1_from" in the trigger is being expanded at alias time, not in the trigger. A simple fix would be to double the %, as then it goes into the trigger as "Resource_%1_from", and then that is expanded later on in the trigger.


AddTriggerEx ("Cargo_A", "*          ( Price per unit: *)", 
    "SetVariable ("Resource_%%1_from", "%%2")", 
    "1", "-1", "0", "", "", "12", "100");

Also I'm not sure about this:

Note "Electronics Rate: $Electronics_difference$";

This isn't Perl, to expand out a variable you need to concatenate it, eg.

Note ("Electronics Rate: " .. Electronics_difference)

-- or

Note ("Electronics Rate: ", Electronics_difference)

-- or

Note (string.format ("Electronics Rate: %i", Electronics_difference))

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Henry Tanner   Finland  (23 posts)  [Biography] bio
Date Reply #2 on Fri 30 Apr 2010 12:07 PM (UTC)  quote  ]
I've returned to the MUD after a long break and along that to this script.

I've learned alot since I last tried to get it to work.

My current problem is resource types that have spaces in their names; they don't bend into variables that well. I've again tried to find something compact to eliminate spaces from a string: "Tibanna Gas" to "TibannaGas".

I know it's there somewhere but I just can't find it. How do I do this?

I got this!
[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.


It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [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.


Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]