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, 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.
 Entire forum ➜ MUSHclient ➜ Lua ➜ Variables not adding when trigger executes.

Variables not adding when trigger executes.

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


Posted by FishOnSpeed   USA  (31 posts)  Bio
Date Tue 19 Feb 2008 03:47 PM (UTC)
Message
<triggers>
<trigger
enabled="y"
group="olc"
match="Mobile * Created"
send_to="12"
sequence="100"
>
<send>require "var"
var.mvnum = var.mvnum + var.one</send>
</trigger>
</triggers>


This is what I have and when it executes it doesn't add the one to mvnum.

<triggers>
<trigger
enabled="y"
group="olc"
match="Room * created."
send_to="12"
sequence="100"
>
<send>require "var"
var.rvnum = var.rvnum + var.one
</send>
</trigger>
</triggers>

I also have this one. It works and is exactly the same as the other one. I'm a little confused so if anyone can shed some light on it for me I would be very thankful.

~FishOnSpeed
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #1 on Tue 19 Feb 2008 04:39 PM (UTC)
Message
Can you display the contents of the "var.lua" file? I have this feeling that you are just reloading the initial values, but you haven't really given a lot of information to go by here.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 19 Feb 2008 07:49 PM (UTC)
Message
Quote:

var.mvnum = var.mvnum + var.one

This is what I have and when it executes it doesn't add the one to mvnum.


Why don't you just add one?

eg.


var.mvnum = var.mvnum + 1


- Nick Gammon

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

Posted by FishOnSpeed   USA  (31 posts)  Bio
Date Reply #3 on Wed 20 Feb 2008 06:08 PM (UTC)
Message
Because it didn't work that way first so I tried it as a variable equal to one to see if it would work.

-- var.lua


var = {} -- variables table

setmetatable (var,
{
-- called to access an entry
__index =
function (t, name)
return GetVariable (name)
end,

-- called to change or delete an entry
__newindex =
function (t, name, val)
local result
if val == nil then -- nil deletes it
result = DeleteVariable (name)
else
result = SetVariable (name, tostring (val))
end
-- warn if they are using bad variable names
if result == error_code.eInvalidObjectLabel then
error ("Bad variable name '" .. name .. "'", 2)
end
end
})

return var

There's my var.lua.

~FishOnSpeed
Top

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 20 Feb 2008 07:40 PM (UTC)
Message
Variables are nil if they don't exist, so your line is effectively:


x = nil + 1


This will give an error.

There are a few ways around this.


  • Simply use the MUSHclient variables configuration window to add the variable mvnum with a value of zero. Then the add will work. You only need to do this once (per variable) as presumably they then get more than one.

  • Somewhere in your script initialize the variables, eg. something like this:

    
    if var.mvnum == nil then
      var.mvnum = 0
    end -- if
    


    This makes it clear that if the variable doesn't exist, you are initializing it.

  • Change your add to look like this:

    
    var.mvnum = (var.mvnum or 0) + 1
    


    By saying "or 0" your are effectively saying "if it is nil, use zero instead".


I certainly would stop using var.one - after all then you have the problem of making sure that var.one is actually 1. And are you going to use var.two if you want to add 2? That is just confusing.

- Nick Gammon

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

Posted by FishOnSpeed   USA  (31 posts)  Bio
Date Reply #5 on Wed 20 Feb 2008 08:28 PM (UTC)
Message
Never mind. It doesn't, it just looked like it did at first.

<variables>
<variable name="mvnum">500785</variable>
</variables>

Theres my variable.

<triggers>
<trigger
enabled="y"
group="olc"
match="Mobile * Created"
send_to="12"
sequence="100"
>
<send>
if var.mvnum == nil then
var.mvnum = 0
end -- if
require "var"
var.mvnum = (var.mvnum or 0) + 1</send>
</trigger>
</triggers>

Theres my trigger.

I'm just really confused because the other trigger I have that uses the exact same stuff works and this one doesn't.

~FishOnSpeed
Top

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #6 on Wed 20 Feb 2008 10:17 PM (UTC)
Message

Check the trigger is actually firing. If not, it won't add 1 to anything.


- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 20 Feb 2008 10:19 PM (UTC)
Message
When I tested that, by sending through "Mobile nick Created" - the trigger fired and added one.

Add some debugging into your script like this:


require "var"

if var.mvnum == nil then
  var.mvnum = 0
end -- if

var.mvnum = (var.mvnum or 0) + 1

Note ("trigger fired, var.mvnum is now ", var.mvnum)


Note that you need to put the "require" before the first line that uses "var". You didn't do that, which makes me suspect the trigger did not even fire.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,052 posts)  Bio   Forum Administrator
Date Reply #8 on Wed 20 Feb 2008 10:20 PM (UTC)
Message
You don't need to do both my suggestions, that is just wasting space. Either have the "if" test, or do the "or 0" stuff. Don't do both.

- Nick Gammon

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

Posted by FishOnSpeed   USA  (31 posts)  Bio
Date Reply #9 on Thu 21 Feb 2008 03:56 PM (UTC)
Message
Okay. It works now and all that great stuff. You where right, the trigger wasn't firing at all.

I was checking everything except one tiny thing that would have fixed everything without ever posting on here. I hadn't changed what the trigger was supposed to match for the new olc output.

Thanks a lot. Still learned some nifty stuff.

~FishOnSpeed
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.


24,831 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.