Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Dumb variable question

Dumb variable question

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Spaz   (2 posts)  Bio
Date Mon 19 Jul 2010 09:03 AM (UTC)
Message
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!
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #1 on Mon 19 Jul 2010 09:27 AM (UTC)
Message
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.)

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Mazarin   (14 posts)  Bio
Date Reply #2 on Wed 21 Jul 2010 12:06 AM (UTC)
Message
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?


Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 21 Jul 2010 03:47 AM (UTC)
Message
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.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Spaz   (2 posts)  Bio
Date Reply #4 on Wed 21 Jul 2010 12:06 PM (UTC)
Message
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!
Top

Posted by Mazarin   (14 posts)  Bio
Date Reply #5 on Wed 21 Jul 2010 08:54 PM (UTC)
Message
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



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.


18,148 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.