I am trying to make a platformer engine by detecting if an object is inbetween the corners of a platform. An error I didn't get before which I didn't do anything wrong. It said expected 'end' after 'function love.load()', but as you can see below, I wrote end.
function love.load()
tile = love.graphics.newImage('grassTile.png')
platformer = {}
platformer.a = {}
platformer.a.x = 600
platformer.a.y = 400
platformer.scroll = 0
platformer.y = 200
end
function love.update(dt)
platformer.a.corner_lb_x = platformer.a.x - (tile:getWidth()/2)
platformer.a.corner_lb_y = platformer.a.y - (tile:getHeight()/2)
platformer.a.corner_rt_x = platformer.a.x + (tile:getWidth()/2)
platformer.a.corner_rt_y = platformer.a.y + (tile:getHeight()/2)
if (0 > platformer.a.corner_lb_x) and (0 < platformer.a.corner_rt_x) and (platformer.y > platformer.a.corner_lb_y) and (platformer.y < platformer.a.corner_rt_y) then
platformer.touching = 1
else if true then
platformer.touching = 0
end
if platformer.touching == 0 then
if love.keyboard.isDown("d") then
platformer.scroll = platformer.scroll - 2
end
end
platformer.y = platformer.y + 1
end
function love.draw()
love.graphics.setBackgroundColor(0,0.2,0.8)
love.graphics.rectangle("fill",400,400,10,10)
end
Wdym line 11 is not closed? I do have an editor with block check too btw. At line 18 that is what I need to type, what ELSE am I supposed to do there? Thank you for replying, and please reply back when you can.
It means my editor flags the function as not having a matching end, it gets eaten at line 18.
"if true then" < why have you came up with this? This line effectively is not exectuted as if true cancels itself. But it eats an extra end.
SuskyTheCorgi wrote: ↑Wed Apr 10, 2024 12:05 am
Wdym line 11 is not closed? I do have an editor with block check too btw. At line 18 that is what I need to type, what ELSE am I supposed to do there? Thank you for replying, and please reply back when you can.
if (0 > platformer.a.corner_lb_x) and (0 < platformer.a.corner_rt_x) and (platformer.y > platformer.a.corner_lb_y) and (platformer.y < platformer.a.corner_rt_y) then
platformer.touching = 1
else if true then
platformer.touching = 0
end
This part makes no sense like this; you set platformer.touching to 1 if those 4 conditions are all true, but then you set it to 0 regardless, since "if true then" is always going to execute... and that also needs an end, hence the error in the first place.
What did you want to do there?
Did you want to just put an else there, like this?:
if (0 > platformer.a.corner_lb_x) and (0 < platformer.a.corner_rt_x) and (platformer.y > platformer.a.corner_lb_y) and (platformer.y < platformer.a.corner_rt_y) then
platformer.touching = 1
else
platformer.touching = 0
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
NOPE. I need that incase the if statement is false, that is definitely what I need. I have not programmed every tile into a read/count system for the if condition because it's just a test. That will make it faster in the future.
Just adding: Youre trying to set a bolean using if cases on a bolean.
Thats just adding extra steps, if you dont have anything else that uses it just do it in one go:
if (0 > platformer.a.corner_lb_x) and (0 < platformer.a.corner_rt_x) and (platformer.y > platformer.a.corner_lb_y) and (platformer.y < platformer.a.corner_rt_y) then
if love.keyboard.isDown("d") then
platformer.scroll = platformer.scroll - 2
end
end