Help with some Error

Hi!

I have just finished making some sprites for the game I’m working on.

Right now I have one goal. Make a character move left and right on the screen.

I already encountered an obstacle- this error that I don’t even know what it means.

It happened since I added this code to main.lua

local char2 = display.newImage(“char2.png”)

char2.x = _W/2

char2.y = _H/2

physics.addBody( character, { friction=1.0, density=1.0, bounce=0} )

When I try to run the thing in the Corona simulator, I get this error (please take a look at the attached picture).

I have no idea what is wrong with the code above, but this error appears only when I add that code, so I’m guessing there is something wrong with it.

Could someone help me explain what I’m doing wrong?

Thanks in advance!

Your attachment didn’t attach.  Can you please type in the error you’re getting?

Is there some code where you create/define “character”? If not then that would explain an error, because the physics engine is trying to add physics to something that does not exist.

If you’re trying to add physics to char2, then just replace “character” with char2:
physics.addBody( char2, { friction = 1.0, density = 1.0, bounce = 0 })

Oh, sorry didn’t notice. Now it’s attached.

I’m going to guess that line 25 is:  char2.x = _W/2

If you read the error message it says can’t index (find) a local variable named char2.  Well the line above it you create a local variable called char2.  So why this error?  I bet if you look in the terminal window that Corona opens up, right above it there will be a line that says something like:

Warning: char2.png not found.

If the app can’t find the image then char2 is nil.

The problem was what Saerothir said- I was actually trying to add physics to something that didn’t exist.

Sorry, it was 2 o’ clock in the morning when I was still working on this game, and that error has confused me.

It was a pretty dumb mistake…I’m ahead now. My character can already move and the sprites are working :slight_smile:

Anyways I appreciate your help, thanks for replying.

Glad I could help. :slight_smile:

Best of luck with your project.

-Saer

Your attachment didn’t attach.  Can you please type in the error you’re getting?

Is there some code where you create/define “character”? If not then that would explain an error, because the physics engine is trying to add physics to something that does not exist.

If you’re trying to add physics to char2, then just replace “character” with char2:
physics.addBody( char2, { friction = 1.0, density = 1.0, bounce = 0 })

Oh, sorry didn’t notice. Now it’s attached.

I’m going to guess that line 25 is:  char2.x = _W/2

If you read the error message it says can’t index (find) a local variable named char2.  Well the line above it you create a local variable called char2.  So why this error?  I bet if you look in the terminal window that Corona opens up, right above it there will be a line that says something like:

Warning: char2.png not found.

If the app can’t find the image then char2 is nil.

The problem was what Saerothir said- I was actually trying to add physics to something that didn’t exist.

Sorry, it was 2 o’ clock in the morning when I was still working on this game, and that error has confused me.

It was a pretty dumb mistake…I’m ahead now. My character can already move and the sprites are working :slight_smile:

Anyways I appreciate your help, thanks for replying.

Glad I could help. :slight_smile:

Best of luck with your project.

-Saer