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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Jscript
. . -> [Subject]  Math - Adding and stuff.

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Math - Adding and stuff.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Pages: 1 2  

Posted by Helpless   (27 posts)  [Biography] bio
Date Sun 15 Jul 2007 02:49 AM (UTC)  quote  ]

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

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #1 on Sun 15 Jul 2007 07:43 PM (UTC)  quote  ]

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

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #2 on Sun 15 Jul 2007 08:27 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Helpless   (27 posts)  [Biography] bio
Date Reply #3 on Mon 16 Jul 2007 03:02 AM (UTC)  quote  ]
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?
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Mon 16 Jul 2007 03:23 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Mon 16 Jul 2007 03:33 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Helpless   (27 posts)  [Biography] bio
Date Reply #6 on Mon 16 Jul 2007 05:59 AM (UTC)  quote  ]
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 :)
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #7 on Mon 16 Jul 2007 06:43 AM (UTC)  quote  ]

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

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Mon 16 Jul 2007 07:00 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Helpless   (27 posts)  [Biography] bio
Date Reply #9 on Tue 17 Jul 2007 05:10 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Tue 17 Jul 2007 05:39 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Helpless   (27 posts)  [Biography] bio
Date Reply #11 on Tue 17 Jul 2007 01:45 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Shaun Biggs   USA  (644 posts)  [Biography] bio
Date Reply #12 on Tue 17 Jul 2007 05:28 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Tue 17 Jul 2007 08:26 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Helpless   (27 posts)  [Biography] bio
Date Reply #14 on Tue 24 Jul 2007 05:57 PM (UTC)  quote  ]
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.
[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.


6,638 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

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]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]