Page 1 of 1

I can't figure out how to work this syntax...

Posted: Sun Feb 03, 2013 6:48 am
by dementia_patient567
My code is pretty short and self explanatory, I think. The issue is in ship.lua with the bullet_spawn and the bullet_draw functions. I want to be able to have any amount of bullets each with their own unique images. You can use the scroll wheel to change ship colors, and thus change the bullet colors. However, the bullets should be their own color, no matter what color the ship is.

For example: I shoot a bullet while blue, I switch to green, previous bullet stays blue, new bullets are green.

I thought my current syntax(and several other failed attempts...) would work right, but apparently not...

It's probably a simple, beginner mistake, but I can't seem to figure it out.

Thanks for your time.
game.zip
(11.34 KiB) Downloaded 131 times

Re: I can't figure out how to work this syntax...

Posted: Sun Feb 03, 2013 5:21 pm
by ejmr
It looks like you're starting out by populating the 'bullet' table with images, and then you go back through that table in bullet_spawn() to associate more information with each bullet. The code crashes as soon as it reaches the call to love.graphics.draw() inside of bullet_draw(), specifically when it reaches the first argument: v.img.

When you call table.insert() you are adding values to the end of the 'bullet' table. So those initial three elements where you call love.graphics.newImage() are still there, and since they are the first three those are the ones the loop inside bullet_draw() will see first. newImage() returns an Image object, but that does not have an 'img' property or anything like that, which is why 'v.img' causes the crash.

I hope that explanation makes sense. If you looped through the 'bullet' table I suspect you would see that it has more elements than you expect it to have.

Re: I can't figure out how to work this syntax...

Posted: Sun Feb 03, 2013 5:48 pm
by dementia_patient567
I feel like a derp >.<

All I had to do was make a separate bullet table for the bullets and for the images