[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  help with scripting

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: help with scripting
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Kevnuke   USA  (83 posts)  [Biography] bio
Date Mon 21 May 2012 02:26 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Fiendish   USA  (848 posts)  [Biography] bio   Global Moderator
Date Thu 10 May 2012 12:02 AM (UTC)  quote  ]

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.

http://aardwolfclientpackage.googlecode.com/
[Go to top] top

Posted by Venhip   (1 post)  [Biography] bio
Date Wed 09 May 2012 08:36 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Thu 25 Aug 2005 03:51 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Wed 24 Aug 2005 10:01 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Wed 24 Aug 2005 09:27 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Wed 24 Aug 2005 07:42 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by Caeser   (22 posts)  [Biography] bio
Date Wed 24 Aug 2005 01:28 AM (UTC)  quote  ]
Message
thanks, that worked perfectly :)
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Tue 23 Aug 2005 11:41 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Caeser   (22 posts)  [Biography] bio
Date Tue 23 Aug 2005 11:22 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Larkin   (278 posts)  [Biography] bio
Date Mon 22 Aug 2005 04:53 PM (UTC)  quote  ]
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)
[Go to top] top

Posted by Caeser   (22 posts)  [Biography] bio
Date Sun 21 Aug 2005 07:19 PM (UTC)  quote  ]
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?
[Go to top] top

Posted by Caeser   (22 posts)  [Biography] bio
Date Tue 09 Aug 2005 12:04 AM (UTC)  quote  ]
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.
[Go to top] 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.


5,565 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]