Ok I am completely lost...

Posted by Kelli on Tue 07 Mar 2006 07:54 AM — 6 posts, 28,007 views.

USA #0
I have tried to figgure out how to do this script. I have seen it done for zmud but can not find one for mush. What I want is some thing to add the amount of gold I get in an hour then report it to me. my problem is getting the trigger variables to work. I really do not know scripting and the help file are not helping me. I am missing some piece of information that will not let it all click in to place. can any one tell me of a book or webiste that is good to learn scripting at? I hate to as any one to just do the script for me as I have alot that I want to do. here is the frist problem that I am coming up on.

I kill a mob and get (x) gold

save x to a variable (total)
save killed mob to (mtotal)

next mob kill I want to save x gold to (total)
save kill mob to (mtotal + 1)

(so on and on for an hour)

at the end of the hour send to the world a report of the
total gold
total mob
gold per mob average
reset total to 0
reset mtotal to 0


I know that it can not be all that hard but I just can not figure it out

I do understand how to make triggers and alise. both of them with and with out variables. I do not understand how to take the varible from the trigger to the script. I have read the GetTriggerVariable help file several time but it did not make sense to me...

where it say (thename, theoutput, thewildcards) is that what i actually put there? or is it some thing eles and if so how do I detrime what it will be?

after all that I know i will have to learn how the timer function works to complete this but I would like to get this adding to begin with. I figure one step at a time


Please any help would be appercated. I am not looking for some on to do it for me just to help me understand.

Kelly
Amended on Tue 07 Mar 2006 07:57 AM by Kelli
Australia Forum Administrator #1
Have you read this?

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6030


It gives detailed descriptions about using scripting, including getting numbers from triggers, and a discussion about variables.
USA #2
ok nick thank you for that other page it has help me to understand this a lot better but i am still doing some thing wrong. If any on can help I thank you. here is the error that mush gives me and the script as i have it now


Error number: -2146827278
Event: Execution of line 963 column 23
Description: Expected identifier
Line in error:
function gold ( test, ^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$, cgold) {
Called by: Immediate execution



function gold (test, ^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$, cgold) {
var ngold;
ngold = parseInt(world.GetVariable( "tgold" )) + parseInt(cgold);
world.SetVariable ("cgold", ngold);
}


tgold is setup and defined as 0 to start with and I have the trigger to call the script set as

^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$

well that is every thing. not sure how i messed up other then trying to attemped something i have no clue on what i am doing still.
Thanks for all the help
USA #3
Um did you literally put ^You get (?p<cgold>.*?) gold coins from the perforated corpse of a (.*?)\.$ in the function header? that should be simply a variable.

function gold (test, line, cgold)

also note that cgold is an array which must be accessed not a single variable. cgold[1] should do it.
USA #4
ok so let me see if I am understanding this... in the header (which i am assuming is the line begining with function) I just need it in

function gold (test, line, cgold[1]) {

is that correct? I though I had to put the entire matching like that called the script in order to use the variable. in this case the amount of gold i got for killing a mob.


and every time i have cgold in the scipt it should be cgold[1] right?

I will try those changes and post the results. thank you for the help..
kelli
Australia Forum Administrator #5
You seem to be confusing the trigger (which matches the text) with the function it calls.

I know you have posted in the Jscript section, but judging by your code you are not heavily committed to using JScript.

Things can be easier in Lua, which is now the recommended script language in MUSHclient.

Here is how you might do your example in Lua. The whole thing can be done in "send to script" without needing a separate script file:


<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="^You get (?P&lt;gold&gt;\d+) gold coins from the perforated corpse of a (?P&lt;mob&gt;.+)\.$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
mobs = mobs or {}  -- make mobs table if it doesn't exist

gold = %&lt;gold&gt;  -- gold from wildcard
mob = "%&lt;mob&gt;"  -- mob name from wildcard

total = (total or 0) + gold   -- count total gold
mobs [mob] = (mobs [mob] or 0) + gold  -- count gold from mob

-- show totals

ColourNote ("white", "blue", "Total gold so far = " .. total)
ColourNote ("white", "blue", "Total gold from " .. mob .. " = " .. mobs [mob])
</send>
  </trigger>
</triggers>




Example output:


You get 15 gold coins from the perforated corpse of a bear.
Total gold so far = 15
Total gold from bear = 15

You get 15 gold coins from the perforated corpse of a kobold.
Total gold so far = 30
Total gold from kobold = 15


The script uses a trigger to match on the message you receive, and in the script adds to a total amount, and also uses the Lua table concept to count totals per mob.