Math - Adding and stuff.

Posted by Helpless on Sun 15 Jul 2007 02:49 AM — 25 posts, 94,018 views.

#0
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.
Amended on Sun 15 Jul 2007 02:50 AM by Helpless
USA #1
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.
Amended on Sun 15 Jul 2007 07:44 PM by Shaun Biggs
USA #2
erm... this line: world.setVariable( "implementor", wildcards[0] should have a ) at the end of it. Sorry.
#3
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?
Australia Forum Administrator #4
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>

Australia Forum Administrator #5
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>


#6
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 :)
USA #7
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.
Amended on Mon 16 Jul 2007 06:06 PM by Shaun Biggs
Australia Forum Administrator #8
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");
#9
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.
Australia Forum Administrator #10
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"
  >
#11
<?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.
USA #12
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
Australia Forum Administrator #13
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.
#14
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.
USA #15
It's probably easiest to just match the lines as they come in. You can have a trigger copy the line into a notepad file within MUSHclient.

You can search the output buffer and grab every line with something like this:

for i = 1,GetInfo(224) do
  if string.find(GetLineInfo(i).text, "wordtofind") then
    AppendToNotepad( "findlines", GetLineInfo(i).text )
  end
  SaveNotepad( "findlines", "C:\filename" )
end
Australia Forum Administrator #16
The Display menu -> Recall Text can be used to search the output buffer for a word or text that is already there. Matching lines are written to a separate window, which can then be saved as a file.
#17
Expected 'To'
Line in error:
for i = 1,GetInfo(224) do

i keep getting that error using what you said.

but i never knew about the Recall Text thing, thanks Nick (and Shaun for trying)
USA #18
Sorry, should have mentioned that the script was for Lua. I completely missed that this was in the Jscript forum.

for i = 1 to world.GetInfo(224) {
  if world.GetLineInfo(i, 1).indexOf( "wordtofind" ) {
    world.AppendToNotepad( "findlines", GetLineInfo(i,1) + "\n" )
  }
world.SaveNotepad( "findlines", "C:\filename" )

Also fixed a few mistakes I had made, like forgetting to put a line break at the end of each line.
#19
Expected '('
Line in error:
for i = 1 to world.GetInfo(224) {
Amended on Sat 28 Jul 2007 07:31 PM by Helpless
USA #20
At some point I'll remember what language I'm trying to deal with.

for (i = 1; i <= world.GetInfo(224), i++) {
  if world.GetLineInfo(i, 1).indexOf( "wordtofind" ) {
    world.AppendToNotepad( "findlines", GetLineInfo(i,1) + "\n" )
  }
world.SaveNotepad( "findlines", "C:\filename" )

#21
Expected ';'
Line in error:
for (i = 1; i <= world.GetInfo(224), i++) {

remember, its suppose to be JScript ;)
USA #22
If you can't fix the typo of a comma needing to be a semicolon, maybe you should pick a language that you are familiar with and run with that. There are several tutorials for pretty much any language you could hope to look for. I've noticed a few errors with the javascript part I jotted down real quickly because I couldn't currently test it on my normal machine. I haven't bothered to try and get javascript running through wine after my last install.
#23
its not like the errors scream out "replace this with this". its only "expected this" and then shows you the line with an error....so helpful.


Expected '('
Line in error:
if world.GetLineInfo(i, 1).indexOf( "wordtofind" ) (
Australia Forum Administrator #24
The problem is, the compiler doesn't really know what you intended, once you break the rules of the language.

Let's take a simple example:


a = b c

Gives error:

Expected ';'
Line in error: 
a = b c


Now there are quite a few things you might have meant, so the compiler can't really say "replace this with that". Here are some examples of what you might have meant:


a = bc  // added a space by mistake
a = b + c  // left out arithmetic operator
a = b - c
a = b / c
a = b * c
a = b (c)  // meant to call function


The intention of the error message is to look at the line in error (and sometimes the previous line is really the problem line), and, using your knowledge of the language, work out what is wrong.