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

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
dementia_patient567
Prole
Posts: 12
Joined: Sun Jan 27, 2013 6:00 am

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

Post 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
User avatar
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...

Post 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.
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經
dementia_patient567
Prole
Posts: 12
Joined: Sun Jan 27, 2013 6:00 am

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

Post 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
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests