Register forum user name Search FAQ

Gammon Forum

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 ➜ Jscript ➜ Math - Adding and stuff.

Math - Adding and stuff.

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


Pages: 1 2  

Posted by Helpless   (48 posts)  Bio
Date Sun 15 Jul 2007 02:49 AM (UTC)

Amended on Sun 15 Jul 2007 02:50 AM (UTC) by Helpless

Message
I need to know how to make it calculate stuff.

You won 20 implementor tokens!
You won 4000 questpoints!
You won 40 immortal tokens!
You win a (Diamond) scratch card!
You won 60 trains!
No matches! You lose! Better luck next time!

Those are some of the things I can win from a card.
I want to be able to turn the calculator on when i start scratching (and it would like...save them somewhere/somehow), then have a alias (manually operated) to sum up everything I have won when im done, and how many times I have lost of course. I've downloaded a script to calculate stuff for something different and I tried to understand it, but I just dont.

Here's where some wildcars or variables would go if you use them:

You won * implementor tokens!
You won * questpoints!
You won * immortal tokens!
You win a * scratch card!
You won * trains!

Example of it reporting:
say You have won X imps, X qps, X imms, X cards, X trains, and lost X amount of times so far.
----------------------------------------------------

Also want an alias to be able to reset all totals to 0 if possible.

If someone could code this for me please...or give me a huge huge huge huge huge huge omega hint on how to do it myself without mind numbing reading...that could be good too.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #1 on Sun 15 Jul 2007 07:43 PM (UTC)

Amended on Sun 15 Jul 2007 07:44 PM (UTC) by Shaun Biggs

Message
Make variables for each statistic you want to track. Have the trigger capture whatever is in the line and add it to that variable. Also, make sure to double check and make sure that the variables are actually there and that you convert them into numbers before trying to add them together. For example, in the trigger that matches "You won * implementor tokens!" you would have this in the send to script part:

imp = world.GetVariable( "implementor" );
if (imp == null) {
  world.setVariable( "implementor", wildcards[0]
} else {
  world.setVariable( "implementor", parseInt(imp) + parseInt(wildcards[0]) )
}

As for the alias to clear it, just set all the variables to 0 or delete them.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #2 on Sun 15 Jul 2007 08:27 PM (UTC)
Message
erm... this line: world.setVariable( "implementor", wildcards[0] should have a ) at the end of it. Sorry.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Helpless   (48 posts)  Bio
Date Reply #3 on Mon 16 Jul 2007 03:02 AM (UTC)
Message
what about an alias to report how many of each I have won so far? and with the stuff you posted, is it already summing them up each time i win X of "whatever"?

maybe if you could show me a script that works with just one of the variables i want, i can move on from there?
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 16 Jul 2007 03:23 AM (UTC)
Message
Try this:


<triggers>
  <trigger
   enabled="y"
   match="You won * implementor tokens!"
   send_to="12"
   sequence="100"
  >
  <send>

imps = GetVariable ("imps");

// first time variable won't exist
if (imps == null)
  imps = "0";

// save for later
SetVariable ("imps", parseInt (imps) + %1)

// note to screen
Note ("You have won " + GetVariable ("imps") + " imps so far")

</send>
  </trigger>
</triggers>


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #5 on Mon 16 Jul 2007 03:33 AM (UTC)
Message
If you are new to scripting, I would use Lua instead of Jscript, it is less fiddly. This is what the trigger looks like in Lua:


<triggers>
  <trigger
   enabled="y"
   match="You won * implementor tokens!"
   send_to="12"
   sequence="100"
  >
  <send>
require "var"  -- converts MUSHclient variables to a Lua table

-- count them
var.imps = (var.imps or 0) + %1

-- note to screen
Note ("You have won " .. var.imps .. " imps so far")
</send>
  </trigger>
</triggers>



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Helpless   (48 posts)  Bio
Date Reply #6 on Mon 16 Jul 2007 05:59 AM (UTC)
Message
is there a way to make it count how many times I win cards? unfortunately its not a number. I'd also like one for counting how many times I lose please. Thanks for all your help so far :)
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #7 on Mon 16 Jul 2007 06:43 AM (UTC)

Amended on Mon 16 Jul 2007 06:06 PM (UTC) by Shaun Biggs

Message
Do the same thing with +1 instead of +wildcards[0]. If there are multiple types of cards, then just name the variable as the card type name, and have the following:
<triggers>
  <trigger
   enabled="y"
   match="You win a (*) scratch card!"
   send_to="12"
   sequence="100"
  >
  <send>

cards = world.GetVariable ("%1");

// first time variable won't exist
if (cards == null)
  cards = "0";

// save for later
world.SetVariable ("%1", parseInt (cards) + 1)

// note to screen
Note ("You have won " + world.GetVariable ("%1") + " %1 cards so far")

</send>
  </trigger>
</triggers>

I really hope I got the right version of %1 in there. I can never remember when I need a set of quotes around those.

ok, fixed up every instance of %1 now.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #8 on Mon 16 Jul 2007 07:00 AM (UTC)
Message
You need to quote them if you are doing that. Just think what would happen if the wildcard got literally inserted.

Say %1 is the word "blue" (but it won't be quoted) then it will generate this:


cards = GetVariable (blue);


That won't work as blue is being treated as a variable, not a literal. So, you need:


cards = GetVariable ("%1");

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Helpless   (48 posts)  Bio
Date Reply #9 on Tue 17 Jul 2007 05:10 AM (UTC)
Message
thanks for all the help, I think I can manage stuff now :)

On another topic, sorta, why doesnt the save_state="y" ever work? it always comes up with an error about being unable to create it or something.
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #10 on Tue 17 Jul 2007 05:39 AM (UTC)
Message
I would need to see your whole plugin header to answer that. Is this a plugin you are talking about? Edit one of the existing ones to see how that is used. For example:


<muclient>
<plugin name="Random_Socials"
  author="Nick Gammon"
  language="Lua"
  id = "e032b4b7db80da78a87dc708"
  purpose = "Displays a random social from time to time"
  save_state = "y"
  date_written="2007-05-03 09:30"
  requires="3.80"
  version = "1.0"
  >

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Helpless   (48 posts)  Bio
Date Reply #11 on Tue 17 Jul 2007 01:45 PM (UTC)
Message
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, April 30, 2007, 12:02 PM -->
<!-- MuClient version 4.01 -->

<!-- Plugin "afestiv" generated by Plugin Wizard -->

<muclient>
<plugin
name="AddThem"
id="a9dea92c93314180d3e365cc"
language="JScript"
date_written="2007-04-30 12:01:37"
purpose="add it"
requires="4.01"
save_state = "y"
version="1.0"
>

</plugin>

thats what it looks like.
keeps saying "Unable to create the plugin save state file".
Its always said this as far as i know, and I know that taking out the save_state line wont give me an error but it also wont save either im sure.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #12 on Tue 17 Jul 2007 05:28 PM (UTC)
Message
Double check your MUSHclient/worlds/plugins/state folder. Make sure it exists, and that you have permission to edit files there. If you do, try matching your worldid-pluginid to a savestate and delete that. Sometimes starting over like that can help.

For instance, if I installed a plugin with the id you just listed into my main world file, I would see this file:
4f290293a1feabfdc0be9e26-a9dea92c93314180d3e365cc-state.xml

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #13 on Tue 17 Jul 2007 08:26 PM (UTC)
Message
See this post:

http://www.gammon.com.au/forum/bbshowpost.php?id=6664

It could something to do with having to change your "plugins" folder in global configuration from a relative path to an absolute path.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Helpless   (48 posts)  Bio
Date Reply #14 on Tue 24 Jul 2007 05:57 PM (UTC)
Message
Is there a way to capture a word from the buffer and have it write to a file the exact line containing that particular word? If it can only be captured "as I go" then thats fine too, but looking for a way to capture the line with the word thats in my buffer already.
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.


87,239 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.