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.
 Entire forum ➜ MUSHclient ➜ Lua ➜ help with scripting

help with scripting

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


Posted by Caeser   (22 posts)  Bio
Date Tue 09 Aug 2005 12:04 AM (UTC)
Message
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.
Top

Posted by Caeser   (22 posts)  Bio
Date Reply #1 on Sun 21 Aug 2005 07:19 PM (UTC)
Message
no body knows how to make an if check if a variable is "greater then or equal to" a number? or less then for that matter?
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #2 on Mon 22 Aug 2005 04:53 PM (UTC)
Message
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)
Top

Posted by Caeser   (22 posts)  Bio
Date Reply #3 on Tue 23 Aug 2005 11:22 PM (UTC)
Message
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):

SetVariable ("bleeding", "%1")

local bleeding

bleeding = GetVariable("bleeding")

if bleeding >= "100" then
Send ("CLOT")
end
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #4 on Tue 23 Aug 2005 11:41 PM (UTC)
Message
You don't want to compare it to a string. You have to first convert it to a number, and then compare it.

See, e.g.:
local bleeding = "500"

if tonumber(bleeding) >= 100 then
    print("woot");
else
    print(":(");
end

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Caeser   (22 posts)  Bio
Date Reply #5 on Wed 24 Aug 2005 01:28 AM (UTC)
Message
thanks, that worked perfectly :)
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #6 on Wed 24 Aug 2005 07:42 PM (UTC)
Message
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.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #7 on Wed 24 Aug 2005 09:27 PM (UTC)
Message
I thought it would coerce it to a number, it is supposed to after all, but look at this:
local bleeding = "500"

if bleeding >= 100 then
    print("woot");
else
    print(":(");
end

Ran it:
$ lua test.lua 
C:\cygwin\usr\local\bin\lua.exe: test.lua:4: attempt to compare number with string
stack traceback:
        test.lua:4: in main chunk
        [C]: ?
However...
local bleeding = "500" + 0
 
if bleeding >= 100 then 
    print("woot");
else
    print(":(");
end
Running it:
$ lua test.lua 
woot


So, I guess that it coerces for arithmetic but not for comparison.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #8 on Wed 24 Aug 2005 10:01 PM (UTC)
Message
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.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #9 on Thu 25 Aug 2005 03:51 AM (UTC)
Message
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.
Top

Posted by Venhip   (1 post)  Bio
Date Reply #10 on Wed 09 May 2012 08:36 PM (UTC)
Message
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
Top

Posted by Fiendish   USA  (2,533 posts)  Bio   Global Moderator
Date Reply #11 on Thu 10 May 2012 12:02 AM (UTC)

Amended on Thu 10 May 2012 12:06 AM (UTC) by Fiendish

Message
Venhip said:

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.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Kevnuke   USA  (145 posts)  Bio
Date Reply #12 on Mon 21 May 2012 02:26 AM (UTC)
Message
Caeser said:

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


38,985 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.