Unknown2007-08-05 19:46:05
I have been trying to make this failsafe timer for my autosipping, but I cannot seem to have it change my drinking flag. What I did was the following, called from a trigger and sent to script:
AddTimer ("fst_drink",0,0,1,"",timer_flag.Enabled + timer_flag.OneShot,"if @flag_drink == 1 then SetVariable ("flag_drink", "0")")
The pattern matches, I have checked that. And if I don't use the command to to change the variable it works, so I guess there is the problem. In the help file it says that the last parameter of the function should be a script. Anyone could help me with this?
AddTimer ("fst_drink",0,0,1,"",timer_flag.Enabled + timer_flag.OneShot,"if @flag_drink == 1 then SetVariable ("flag_drink", "0")")
The pattern matches, I have checked that. And if I don't use the command to to change the variable it works, so I guess there is the problem. In the help file it says that the last parameter of the function should be a script. Anyone could help me with this?
Unknown2007-08-05 20:09:56
QUOTE(Shinth @ Aug 5 2007, 09:46 PM) 431577
I have been trying to make this failsafe timer for my autosipping, but I cannot seem to have it change my drinking flag. What I did was the following, called from a trigger and sent to script:
The pattern matches, I have checked that. And if I don't use the command to to change the variable it works, so I guess there is the problem. In the help file it says that the last parameter of the function should be a script. Anyone could help me with this?
The pattern matches, I have checked that. And if I don't use the command to to change the variable it works, so I guess there is the problem. In the help file it says that the last parameter of the function should be a script. Anyone could help me with this?
If I'm not mistaken, you need to provide a function and not a snippet of code to AddTimer(). That provided function also cannot take parameters other than the preset ones MUSHclient sends, first one being the name of the "callee", fst_drink in this case. So you'd need something like this.
AddTimer ("fst_drink",0,0,1,"",timer_flag.Enabled + timer_flag.OneShot,"resflag")
function resflag(name)
if name == "fst_drink" then
if @flag_drink == 1 then
SetVariable ("flag_drink", "0")
end
end
end
Due to not having used MUSHclient for quite some time, I reserve myself for posible errs. Feel free to correct me and point those out if you see them.
Unknown2007-08-05 21:03:28
Gotta watch those quotes, too. You unquoted and re-quoted in the middle of the last parameter, which gives unexpected results.
Unknown2007-08-06 05:39:25
Updated function:
AddTimer ("fst_drink",0,0,1,"",timer_flag.Enabled + timer_flag.OneShot,"resflag(fst_drink)")
function resflag(name)
if name == fst_drink then
if GetVarible("flag_drink") == 1 then
SetVariable ("flag_drink", "0")
end
end
end
Edit: If I call the function resflag(fst_drink) from the immediate window, it works, but if the timer calls it, it doesn't. I think I will go ask on the mush forums, this is really annoying.
AddTimer ("fst_drink",0,0,1,"",timer_flag.Enabled + timer_flag.OneShot,"resflag(fst_drink)")
function resflag(name)
if name == fst_drink then
if GetVarible("flag_drink") == 1 then
SetVariable ("flag_drink", "0")
end
end
end
Edit: If I call the function resflag(fst_drink) from the immediate window, it works, but if the timer calls it, it doesn't. I think I will go ask on the mush forums, this is really annoying.
Theomar2007-08-06 07:17:13
Get rid of the "resflag(fst_drink)," and replace it with "resflag".
Two reasons: A) I believe CroX is correct in that only functions that can be done in AddTimer are ones that are passed the name, output, wildcs parameters. Basically, in order to properly work, you'd have to make resflag like this:
Names passed by MUSH features, such as aliases/timers/triggers, are passed as strings. Also, when using MUSH variables, they have a tendency to not like storing numbers as numbers, so always use the tonumber() function to make sure you're comparing numbers.
The second reason I changed it is the original, "resflag(fst_drink)", was passing a variable with the pointer fst_drink. Since you were refering to the name of the timer, it would be "resflag('fst_drink')" but as I said, I'm pretty sure you can't call that type of function in AddTimer/Trigger/Alias/etc.
Two reasons: A) I believe CroX is correct in that only functions that can be done in AddTimer are ones that are passed the name, output, wildcs parameters. Basically, in order to properly work, you'd have to make resflag like this:
CODE
function resflag(name, output, wildcs)
            if name == "fst_drink" then
              if tonumber(GetVariable("flag_drink")) == 1 then
                  SetVariable("flag_drink", "0")
              end
            end
end
            if name == "fst_drink" then
              if tonumber(GetVariable("flag_drink")) == 1 then
                  SetVariable("flag_drink", "0")
              end
            end
end
Names passed by MUSH features, such as aliases/timers/triggers, are passed as strings. Also, when using MUSH variables, they have a tendency to not like storing numbers as numbers, so always use the tonumber() function to make sure you're comparing numbers.
The second reason I changed it is the original, "resflag(fst_drink)", was passing a variable with the pointer fst_drink. Since you were refering to the name of the timer, it would be "resflag('fst_drink')" but as I said, I'm pretty sure you can't call that type of function in AddTimer/Trigger/Alias/etc.
Unknown2007-08-06 08:56:45
QUOTE(Theomar @ Aug 6 2007, 10:17 AM) 431733
The second reason I changed it is the original, "resflag(fst_drink)", was passing a variable with the pointer fst_drink. Since you were refering to the name of the timer, it would be "resflag('fst_drink')" but as I said, I'm pretty sure you can't call that type of function in AddTimer/Trigger/Alias/etc.
You were right, it works now. Thank you very much. And I would rather use GetVariable("flag_drink") == "1" than to call another function. It's faster and less to write.