Jump to content

A Slightly Unrelated Lua Problem [SOLVED]


Ontogenesis

Recommended Posts

So I've decided to just get on with a 2D game project that's been on my mind a lot recently.

I using LOVE, a Lua 2D engine.

Unfortunately, I've run into a problem already with a piece of code that highlights grid squares.

 

Full details can be found here: https://love2d.org/forums/viewtopic.php?f=4&t=72078

 

I was wondering if any competent coders can identify the source of my problem? Basically if I include an if function for the mouse over, the highlighting doesn't work. However, if I take it out, it works fine. But the line of code that switches the if statement between true and false is in the same bit it gets the co-ordinates to draw the highlighting tile... so it must be able to run the chunk fine, I don't understand why it doesn't work.

 

This is the problem area:

--compares mouse x and y to the x and y grid co-ordinates stored in a table    if ((x >= gx) and (x <= gx+s)) and ((y >= gy) and (y <= gy+s)) then        highlight.ini = true --enables drawing        highlight.x = gx        highlight.y = gy        else        highlight.ini = false --disables drawing        end--in the draw callbackif highlight.ini thenlove.graphics.draw(high, highlight.x, highlight.y)end

^ This doesn't work.

 

But this does:

--compares mouse x and y to the x and y grid co-ordinates stored in a table    if ((x >= gx) and (x <= gx+s)) and ((y >= gy) and (y <= gy+s)) then        highlight.ini = true        highlight.x = gx        highlight.y = gy        else        highlight.ini = false        end--in the draw callback--if highlight.ini thenlove.graphics.draw(high, highlight.x, highlight.y)--end

Ahhh

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...