Hello. I play the mud called Achaea and I am trying to make a trigger that runs a script for it.
The trigger is supposed to make on "You bleed * health."
It then sends the wildcard into the variable "bleeding"
I want a script after that to check if the variable bleeding is greater than or equal to 100, and if so it should use CLOT. Now, I don't know how to do different testing signs like that, so a brief tutorial on those types of test conditions would be great valued.
Have you looked at the Lua documentation? This is really a very, very simple thing you're asking, which makes me believe that you haven't looked for an answer yet.
http://www.lua.org
http://www.lua.org/pil (Programming in Lua, which I prefer)
I tried that already, but it doesn't work. I want it to be >=, but apparently I have it wrong since any number it recieves it performs CLOT. Here is my full script (in a trigger, set to Send to Script... not reg expression):
I'm sorry. I was assuming that you did the comparison directly in the trigger and that you didn't convert it into a string and save it in a variable. I don't see the need to save it, since you're just going to clot from this trigger and never use that bleeding value again, right?
You bleed * health.
if %1 >= 100 then
Send("clot")
end
No quotes around the %1 allows Lua to implicitly convert the value into a number when MUSHclient expands the value, basically. Should work, but I wouldn't bet my life on it.
Comparisons first check the types (if different, returns false) then goes on to the value.
However, even if he doesnt want to save it for later:
SetVariable ("bleeding", %1)
local bleeding
bleeding = %1
if bleeding >= 100 then
Send ("CLOT")
end
will work just fine. (stores bleeding as a number, and sets the variable, for later use. No need to set it, only to get it again two lines later.
Of course, if you don't need to save it, then you might as well get rid of the setvariable as well. (and if you dont need your local variable for other things, then do what Larkin suggested, and just use %1 straight in the comparison.
The %1 %2 etc comparisons are basically text-replaces, it happens before the script sees it, so you can get creative and even include functions or whole lines of scripts, or whatever else.
Right. That's why I suggested not saving it with SetVariable, because the GetVariable will return it as a string, no matter how you think you stored it. Doing the comparison directly or using a Lua local variable will type it as a number.
Hey, im trying to do a comparison in lua, im running it in a game though with something to interpret new commands that have been put in; the suggested comparison method doesnt work for me
1 t = 0
2 c = 1
3 while turtle.detectUp() do
4 turtle.placeDown()
5 turtle.forward()
6 t = t+1
7 if turtle.GetItemCount(tonumber(c)) == 0 then
8 c = c+1
9 end
10 end
11 print(""..t.." tracks laid.")
line 7 where it says "turtle.GetItemCount(tonumber(slot)) == 0 then"
im trying to compare the c variable obviously, but it returns
"Attempted to call nil"
Any ideas?
Hey, im trying to do a comparison in lua, im running it in a game though with something to interpret new commands that have been put in; the suggested comparison method doesnt work for me
1 t = 0
2 c = 1
3 while turtle.detectUp() do
4 turtle.placeDown()
5 turtle.forward()
6 t = t+1
7 if turtle.GetItemCount(tonumber(c)) == 0 then
8 c = c+1
9 end
10 end
11 print(""..t.." tracks laid.")
line 7 where it says "turtle.GetItemCount(tonumber(slot)) == 0 then"
im trying to compare the c variable obviously, but it returns
"Attempted to call nil"
Any ideas?
Thanks
c is already a number so the call to tonumber() does nothing useful.
To know what caused the error we probably need to know what turtle.GetItemCount() does. Either you set tonumber to nil somewhere (silly) or turtle.GetItemCount doesn't exist. Or something inside turtle.GetItemCount doesn't exist. Or maybe something else doesn't exist. We don't know because you haven't shown enough of the error message or enough of the code for us to reach any conclusions.
Hello. I play the mud called Achaea and I am trying to make a trigger that runs a script for it.
The trigger is supposed to make on "You bleed * health."
It then sends the wildcard into the variable "bleeding"
I want a script after that to check if the variable bleeding is greater than or equal to 100, and if so it should use CLOT. Now, I don't know how to do different testing signs like that, so a brief tutorial on those types of test conditions would be great valued.
if %1 >= 100 then
Send ("clot")
end
it's kinda that simple. And why aren't you using regex?
^You bleed (\d+) health.$
..would guarantee that it's a number and keep people from illusioning you a bleed symptom.