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 ➜ Global variable used within triggers.

Global variable used within triggers.

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


Posted by Ductape   (5 posts)  Bio
Date Wed 12 Aug 2009 07:15 AM (UTC)
Message
Hi there, new to lua and I am trying to learn some things so i can build more advanced scripts in the future.

I am trying to use a variable in a trigger, and also in a script that send to the mud all from within a plugin.

Pastebin is here:
http://pastebin.com/m3a86d453

Line 27 I attempt to declare a global

Line 52 I attempt to use it in a trigger

The script section starting at line 98 works perfectly. What am I doing wrong for the Trigger section?

Heres the code for those who dont want to clicky pastebin:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Monday, July 27, 2009, 8:13 PM -->
<!-- MuClient version 4.40 -->

<!-- Plugin "repairgrinder" generated by Plugin Wizard -->

<muclient>
<plugin
   name="repairgrind2"
   author="Terensque"
   id="ce3de8b3aa85d6f6eba44dac"
   language="Lua"
   purpose="grind repair with tv"
   date_written="2009-07-27 20:12:59"
   requires="4.40"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Declare a global for the triggers   -->

repairobject = "television"

<!--  Triggers  -->

<triggers>


  <trigger
   enabled="y"
   match="^It's completely destroyed.$|^Sybian curses in frustration and gives up.$|^You fixed some of the damage.$"
   regexp="y"
   name="needs_repair"
   script="repair"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   match="You fixed all of the damage."
   script="repair"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   match="^Sybian's (.*?) against (.*?) (repairobject).$|^Sybian's (.*?) puts a dent in (.*?) (repairobject).$|^Sybian's (.*?) into (.*?) (repairobject)(.*?)$|^Sybian's (.*?) scuffs (.*?) (repairobject)(.*?)$"
   regexp="y"
   name="check_repair"
   script="repair"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   match="^It's (.*?) damaged.$|^It's a little dinged up.$"
   regexp="y"
   name="needs_kill"
   script="repair"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="y"
   match="^[ You earned (.*?) IP in repair! ]$|^[ You spent (.*?) for (.*?) IP in repair! ]$"
   regexp="y"
   name="check_grind"
   send_to="10"
   sequence="100"
  >
  <send>
   score
  </send>
  </trigger>

  <trigger
   enabled="y"
   match="(.*?) you can for today(.*?)$"
   regexp="y"
   name="end_grind"
   script="repair"
   sequence="100"
  >
  </trigger>

</triggers> 
<script>

local repairobject
repairobject = "television"

function repair (sTrig)
  if sTrig == "needs_repair" then
    Send ("repair " .. repairobject)
  elseif sTrig == "needs_kill" then
    Send ("kill " .. repairobject)
  elseif sTrig == "check_repair" then
    Send ("examine " .. repairobject)
  elseif sTrig == "end_grind" then
    Print ("Repair grind complete")
  else
    Send ("kill " .. repairobject)
  end
end -- repair
</script>

</muclient>
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 12 Aug 2009 07:39 AM (UTC)
Message
I assume this is the troubling line:


match="^Sybian's (.*?) against (.*?) (repairobject).$|^Sybian's (.*?) puts a dent in (.*?) (repairobject).$|^Sybian's (.*?) into (.*?) (repairobject)(.*?)$|^Sybian's (.*?) scuffs (.*?) (repairobject)(.*?)$"


First, I would be a little cautious about the brackets. I may be wrong, but I would parenthesize the various things you are checking, like this:


match="(^Sybian's (.*?) against (.*?) (repairobject).$)|(^Sybian's (.*?) puts a dent in (.*?) (repairobject).$)|(^Sybian's (.*?) into (.*?) (repairobject)(.*?)$)|(^Sybian's (.*?) scuffs (.*?) (repairobject)(.*?))$"


The much bigger problem here though, is you are confusing script variables with MUSHclient internal variables, which in any case you haven't asked it to use.

To simplify, I will look at a single branch of your match, eg.


match="^Sybian's (.*?) against (.*?) (repairobject).$"


This is going to match "repairobject" not what that variable expands to. You need to put a @ in front of it, like this:


match="^Sybian's (.*?) against (.*?) (@repairobject).$"


Then, you need to tell it to expand variables, by checking the "expand variables" checkbox.

If you had done that, I would have seen:


 expand_variables="y"


... in your trigger definition.

Next, a MUSHclient variable is not a Lua variable.
So, you might change:


local repairobject
repairobject = "television"


to:


local repairobject
repairobject = "television"
SetVariable ("repairobject", repairobject)


Now the MUSHclient variable "repairobject" is going to have "television" in it. Now the trigger will expand @repairobject to "television" and things will start to work.


- Nick Gammon

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

Posted by Ductape   (5 posts)  Bio
Date Reply #2 on Mon 17 Aug 2009 12:31 AM (UTC)
Message
This worked perfect.
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.


13,718 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.