Page 1 of 1

Bullets that don't shoot.

Posted: Fri Feb 12, 2016 5:30 pm
by W3LF
Hi again, i'm having a bit of troubles with bullets.
I followed a tutorial on love's wiki, but they don't want to work.

Here is my code:
bullet.lua (i think the problem is here): http://pastebin.com/MafSWDak
Or if you want, a .love file with the entire code: https://www.dropbox.com/s/m5fc58iqm8dww ... .love?dl=0

Thanks to everyone that will have the patience to read the code and maybe help me out :D

Re: Bullets that don't shoot.

Posted: Fri Feb 12, 2016 6:12 pm
by ivan
The pastebin code looks fine.
I didn't read the rest but

Code: Select all

function UPDATE_BULLET(dt)
    bullet.update()
    love.mousepressed()
end
Should be:

Code: Select all

function UPDATE_BULLET(dt)
    bullet.update(dt)
    love.mousepressed(x, y, button) -- not sure what args you would pass there
end

Re: Bullets that don't shoot.

Posted: Fri Feb 12, 2016 6:19 pm
by W3LF
ivan wrote:The pastebin code looks fine.
I didn't read the rest but

Code: Select all

function UPDATE_BULLET(dt)
    bullet.update()
    love.mousepressed()
end
Should be:

Code: Select all

function UPDATE_BULLET(dt)
    bullet.update(dt)
    love.mousepressed(x, y, button) -- not sure what args you would pass there
end
Thanks for the help, but it still doesn't work :c

Re: Bullets that don't shoot.

Posted: Fri Feb 12, 2016 7:00 pm
by OrbitalBlueprint
.

Re: Bullets that don't shoot.

Posted: Fri Feb 12, 2016 8:27 pm
by zorg
I also see in the pastebin snippet that you define bullet.speed, but nowhere are any numeric keys defined inside bullet, much less a dx or dy member for them.

Re: Bullets that don't shoot.

Posted: Sat Feb 13, 2016 8:26 am
by W3LF
zorg wrote:I also see in the pastebin snippet that you define bullet.speed, but nowhere are any numeric keys defined inside bullet, much less a dx or dy member for them.

Code: Select all

local bulletDx = bullet.speed * math.cos(angle)
local bulletDy = bullet.speed * math.sin(angle)
I don't get what you mean, sorry :c

Re: Bullets that don't shoot.

Posted: Sat Feb 13, 2016 10:25 am
by zorg
W3LF wrote:I don't get what you mean, sorry :c
This part:

Code: Select all

function bullet.update(dt)
    for i,v in ipairs(bullet) do
        v.x = v.x + (v.dx * dt)
        v.y = v.y + (v.dy * dt)
    end
end
v would be bullet, but bullet does not have any members with number keys (only speed, x, y, etc...), and even if it would, they would still lack the dx and dy keys.

Re: Bullets that don't shoot.

Posted: Sat Feb 13, 2016 3:19 pm
by W3LF
zorg wrote: This part:

Code: Select all

function bullet.update(dt)
    for i,v in ipairs(bullet) do
        v.x = v.x + (v.dx * dt)
        v.y = v.y + (v.dy * dt)
    end
end
v would be bullet, but bullet does not have any members with number keys (only speed, x, y, etc...), and even if it would, they would still lack the dx and dy keys.


The fact is, I literally copypasted it from Love's wiki, but it still doesnt work.
I'm new to programming so I have no idea of what's wrong, could you please tell me how I should do it then?

Re: Bullets that don't shoot.

Posted: Sat Feb 13, 2016 5:11 pm
by MadByte
Take a look at this basic shooting example:
bulletExample.love
It should make clear what is going wrong with your code.

Re: Bullets that don't shoot.

Posted: Sun Feb 14, 2016 3:07 pm
by W3LF
MadByte wrote:Take a look at this basic shooting example:
bulletExample.love
It should make clear what is going wrong with your code.
Thanks a lot :D