Persistent variable, two different triggers

Posted by Mavega on Tue 22 Jan 2013 07:32 AM — 7 posts, 24,644 views.

#0
Hi Mr. Gammon, you seem like such an intelligent person and I would be forever grateful for your help with my latest problem.


Trigger #1 - "Text_AAAAAA"

(Set variable X to "1")
(Send variable like, "say Hello 'x'")

Trigger #2 - "Text_BBBBBB"

(Set variable X to 2X [so multiply it by 2 and store it]
(Send new X like, "say Hello 'x'")


So basically... if trigger "AAAAAA" occurs, we reset variable X and send it in a command to the server.

If trigger "BBBBBB" occurs, we multiply X by 2 and then send that to the server.


Can you please help me? I feel like I don't even know where to start because I don't need variable X to persist through each session - it only has to stay alive until Trigger "AAAAA" is called again.
#1
Example test case:


Server says: "AAAAAA"
I say, "Hello 1"

Server says: "BBBBBB"
I say, "Hello 2"

Server says: "BBBBBB"
I say, "Hello 4"

Server says: "BBBBBB"
I say, "Hello 8"

Server says: "AAAAAA"
I say, "Hello 1"

Server says: "BBBBBB"
I say, "Hello 2"


etc etc etc
Australia Forum Administrator #2
Can you make a try, and show what you did?

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


Variables persist, this should be simple to do.
#3
I have 2 different trigger codes...

<triggers>
  <trigger
   enabled="y"
   match="AAAAAA"
   send_to="12"
   sequence="100"
  >
  <send>
x = tonumber (GetVariable ("x"))
x = x * 2
SetVariable ("x", x)
Send ("counter currently at ", x, " steps")</send>
  </trigger>
</triggers>



<triggers>
  <trigger
   enabled="y"
   match="BBBBBB"
   send_to="12"
   sequence="100"
  >
  <send>
SetVariable("x", "2")
Send ("counter reset to 2")</send>
  </trigger>
</triggers>
Australia Forum Administrator #4
The examples you posted are the opposite of what you said (regarding AAAAAA and BBBBBB) but can be simplified:


<triggers>
  <trigger
   enabled="y"
   match="AAAAAA"
   send_to="12"
   sequence="100"
  >
  <send>
x = (x or 1) * 2
Note ("counter currently at ", x, " steps")
</send>
  </trigger>

  <trigger
   enabled="y"
   match="BBBBBB"
   send_to="12"
   sequence="100"
  >
  <send>
x = 1
Note ("counter reset to 1")
</send>
  </trigger>
</triggers>

Australia Forum Administrator #5
The Lua variable "x" (you might want to give it a longer name) persists inside the script space for that session.
#6
Yes you're right. I made a mistake and switched BBBBBB and AAAAAA in the code.


I'm going to try your fixes now, thanks.