I am trying to make a flappy bird replica but my "createrec" function does not seem to work... It is very possible that it is a different problem because as my name suggests, I am very bad.
This is the code:
function love.load()
love.physics.setMeter(64)
world = love.physics.newWorld(0, 9*64, true)
recs = {}
objects = {}
objects.ball = {}
objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic")
objects.ball.shape = love.physics.newCircleShape(20)
objects.ball.fixture = love.physics.newFixture(objects.ball.body,
objects.ball.shape, 1)
objects.ball.fixture:setRestitution(0.9)
love.graphics.setBackgroundColor(0.41, 0.53, 0.97)
love.window.setMode(650, 650)
end
function love.update(dt)
world:update(dt)
end
function love.draw()
love.graphics.setColor(0.76, 0.18, 0.05)
love.graphics.circle("fill", objects.ball.body:getX(),
objects.ball.body:getY(), objects.ball.shape:getRadius())
for i,r in ipairs(recs) do
love.graphics.rectangle("line", r.x, r.Y, r.width, r.height)
end
end
function love.keypressed(key)
if key == "up" then
objects.ball.body:applyForce(0, -4000)
end
if key == "down" then
function createRecs()
end
end
function createRecs()
local rec = {}
rec.X = objects.ball.body:getX() + 300
rec.Y = love.math.random(200, 700)
rec.width = 50
rec.height = rec.Y
table.insert(recs, rec)
end
end
Thank you
My Function isn't activating, please help
Re: My Function isn't activating, please help
What is the error and which line is it on?
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Turn-based PBEM horse stable (racing) management sim: https://togfox.itch.io/horse-stable-manager
https://discord.gg/HeHgwE5nsZ
Re: My Function isn't activating, please help
Please use [code]...[/code] tags to format code, so that it's correctly formatted. I've added them for you in the quote above.BigNoob wrote: ↑Sun Apr 18, 2021 4:32 am I am trying to make a flappy bird replica but my "createrec" function does not seem to work... It is very possible that it is a different problem because as my name suggests, I am very bad.
This is the code:
Thank youCode: Select all
function love.load() love.physics.setMeter(64) world = love.physics.newWorld(0, 9*64, true) recs = {} objects = {} objects.ball = {} objects.ball.body = love.physics.newBody(world, 650/2, 650/2, "dynamic") objects.ball.shape = love.physics.newCircleShape(20) objects.ball.fixture = love.physics.newFixture(objects.ball.body, objects.ball.shape, 1) objects.ball.fixture:setRestitution(0.9) love.graphics.setBackgroundColor(0.41, 0.53, 0.97) love.window.setMode(650, 650) end function love.update(dt) world:update(dt) end function love.draw() love.graphics.setColor(0.76, 0.18, 0.05) love.graphics.circle("fill", objects.ball.body:getX(), objects.ball.body:getY(), objects.ball.shape:getRadius()) for i,r in ipairs(recs) do love.graphics.rectangle("line", r.x, r.Y, r.width, r.height) end end function love.keypressed(key) if key == "up" then objects.ball.body:applyForce(0, -4000) end if key == "down" then function createRecs() end end function createRecs() local rec = {} rec.X = objects.ball.body:getX() + 300 rec.Y = love.math.random(200, 700) rec.width = 50 rec.height = rec.Y table.insert(recs, rec) end end
You have an unbalanced 'end', because you're defining createRecs() when you actually want to call it.
This part:
Code: Select all
if key == "down" then
function createRecs()
end
Code: Select all
if key == "down" then
createRecs()
end
Who is online
Users browsing this forum: No registered users and 1 guest