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 ➜ Programming ➜ General ➜ lua help

lua help

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


Posted by PL3X   (3 posts)  Bio
Date Thu 27 Dec 2007 01:30 AM (UTC)
Message
Hey, I quite new to lua and there are a few things that i cant get to work..

1.i have used the collsiion detection script as follows

function collisionCheck(object)
if (Player.x + playerWidth > object.x) and (Player.x < object.x + object.width) and (Player.y + playerHeight > object.y) and (Player.y < object.y + object.height) then
Player.x = oldx
Player.y = oldy
end
end

that works fine but when I try and use the same thing replacing Player with Enemy then Enemy just goes straight through it.

and also the following section doesnt work either:

if Player.y = Enemy.y and Player.x = Enemy.x then
screen:clear
screen:print(100,200,"you loose",red)
end

Please help
Top

Posted by Darwin   USA  (125 posts)  Bio
Date Reply #1 on Thu 27 Dec 2007 02:11 AM (UTC)
Message
Quote:
if Player.y = Enemy.y and Player.x = Enemy.x then
screen:clear
screen:print(100,200,"you loose",red)
end

The = is used for assignment of values not comparison. What you need is ==.
if Player.y == Enemy.y and Player.x == Enemy.x then
screen:clear
screen:print(100,200,"you loose",red)
end
Top

Posted by PL3X   (3 posts)  Bio
Date Reply #2 on Thu 27 Dec 2007 03:28 AM (UTC)
Message
Thanks DArwin although now it says function arguments expected near 'screen' :( any ideas?
Top

Posted by Nick Gammon   Australia  (23,102 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 27 Dec 2007 05:24 AM (UTC)
Message
To call a function you must supply an argument list even if it is empty. That is:


screen:clear ()

- Nick Gammon

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

Posted by PL3X   (3 posts)  Bio
Date Reply #4 on Thu 27 Dec 2007 05:36 AM (UTC)
Message
ok thanks mate, sorry for the dum question im very new to lua and have only done a few tutorials all of your help is much appreciated :D
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.


15,808 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.