Dumb variable question

Posted by Spaz on Mon 19 Jul 2010 09:03 AM — 6 posts, 24,499 views.

#0
Apologies for the dumb question (I'm a new convert from Zmud and trying to recreate my triggers and such from there).

How do I increment a certain variable anytime a particular pattern matches?

I've read http://www.gammon.com.au/forum/?id=4904 but I'm not too clear on what requiring does -- or even where to do it. Taking the explanations and snippets and turning it into "Click here, type things there, etc" was beyond me. (Sorry, I'm a total rookie when it comes to lua, or any other type of scripting.)

My example should be simpler than that, actually, since I only want to increment by 1 each time. For example, to track arena deaths, I just want a trigger to match on "*You are DEAD!" and have that set @deaths to @deaths + 1.

I'd also like an alias to reset it to 0 (not nil), so I can reset my stats without logging. So "ArenaReset" should set @deaths to 0.

Are these doable without scripting?

Thanks in advance!
USA #1
Mmmm.... I don't think you can get away with not using scripting here. It's the addition you need that's fallen into the domain of scripting.

It's as simple as SetVariable("deaths", @deaths + 1), or if you want to be exact about it, SetVariable("deaths", tonumber(GetVariable("deaths")) + 1). I prefer the second form just because it's clearer what's involved, but either works. (For the former, just make sure to have "expand variables" checked.)
#2
Spaz said:
How do I increment a certain variable anytime a particular pattern matches?

My example should be simpler than that, actually, since I only want to increment by 1 each time. For example, to track arena deaths, I just want a trigger to match on "*You are DEAD!" and have that set @deaths to @deaths + 1.

I'd also like an alias to reset it to 0 (not nil), so I can reset my stats without logging. So "ArenaReset" should set @deaths to 0.


On the contrary, as a newbie I thought it was an intresting question (with an as well intresting answer). The answer gave me a lot.

I myself would like to know how to make a trig that fires only on certain event, like every second time it matches? What is the syntax to that, I receive my fight prompt twice every round and would like to react - but only once every round.

Thanks for your kind help.

P.S. Would there be some interest in a thread meant for "stupid" (=basic) newbie-questions?


Australia Forum Administrator #3
I think someone said the only dumb question is the one that isn't asked.

To make a trigger fire every second time ... well you want it to fire every time, but you only need to "react" every second time. This is where scripting helps.

eg.


if already_fired then
  -- do something here
  already_fired = false
else
  already_fired = true
end -- if


That bit of code flips a flag (already_fired). The first time it just sets it to true (it will default to nil which is considered false). Second time, you do some action, and set it back to false.

Spaz said:

I'd also like an alias to reset it to 0 (not nil), so I can reset my stats without logging. So "ArenaReset" should set @deaths to 0.


There are a few ways you could do it, but this simple alias just moves "0" to the variable "deaths".


<aliases>
  <alias
   match="ArenaReset"
   enabled="y"
   variable="deaths"
   send_to="9"
   sequence="100"
  >
  <send>0</send>
  </alias>
</aliases>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

#4
Outstanding. Got it all figured out. Thanks for the help everyone. =D

I'm liking MC more and more -- this is a great piece of software Nick!
#5
Nick Gammon said:
To make a trigger fire every second time ... well you want it to fire every time, but you only need to "react" every second time. This is where scripting helps.
eg.

if already_fired then
  -- do something here
  already_fired = false
else
  already_fired = true
end -- if




Thank you, it works like a dream!



// Mazarin