Calculation in Variables

Posted by Ventrilo on Fri 14 Apr 2006 02:43 PM — 6 posts, 22,668 views.

#0
Hi,

Could someone please help me on how to calculate with variants and triggers, then display it without having to use any scripts?

For example:
I want MushClient to capture the trigger on 'You have been saved.', count it to a variable named 'test', so whenever that text pops up, 'test' would have the counter.

What I've got so far:
Trigger works, output it to a var named 'test', altho 'test' only contains '+1' regardless of how many times that text pops up.
Australia Forum Administrator #1
Can you show us what you did? See:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4776
#2
This is what I've got:

<triggers>
<trigger
enabled="y"
match="^You have been saved."
send_to="9"
sequence="100"
variable="test"
>
<send>+1</send>
</trigger>
</triggers>


It's just a test on what I'll try to expand without programming/scripting knowledge (e.g: level up calculation, etc.)

Thanks Nick!
Australia Forum Administrator #3
This is how I would do that. You need to enable scripting and make Lua your scripting language.

For more details about doing that, see:

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




<triggers>
  <trigger
   custom_colour="3"
   enabled="y"
   match="^You have been saved\.$"
   regexp="y"
   send_to="12"
   sequence="100"
   variable="test"
  >
  <send>
SetVariable ("test", (GetVariable ("test") or 0) + 1)
Note ("Saved count is now " .. GetVariable ("test"))
</send>
  </trigger>
</triggers>



The "or 0" part allows for the initial case of the variable not existing.

Your trigger looked like a regular expression (with the ^ at the start) but you had not checked the "regular expression" box.
#4
Thanks Nick,

I read about your post on the Lua script and did the following:
I opened immediate window on MushClient and paste your solution, after I've chosen Lua as my script preference. Altho when i ran the script it says:

Error number: 0
Event: Compile error
Description: [string "Immediate"]:1: unexpected symbol near `<'
Called by: Immediate execution

Thanks
Australia Forum Administrator #5
Read this post:

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

Only part of that was the script, the rest was a trigger in the XML format used by MUSHclient.