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.
I can't figure out how to work this syntax...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 12
- Joined: Sun Jan 27, 2013 6:00 am
- ejmr
- Party member
- Posts: 302
- Joined: Fri Jun 01, 2012 7:45 am
- Location: South Carolina, U.S.A.
- Contact:
Re: I can't figure out how to work this syntax...
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.
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.
-
- Prole
- Posts: 12
- Joined: Sun Jan 27, 2013 6:00 am
Re: I can't figure out how to work this syntax...
I feel like a derp >.<
All I had to do was make a separate bullet table for the bullets and for the images
All I had to do was make a separate bullet table for the bullets and for the images
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests