is it possible to do nested if statements

hello! Can I do nested ifs in corona? Below is what im trying to accomplished.

display.setStatusBar( display.HiddenStatusBar )
–multitouch
system.activate(“multitouch”)
–physics stuff
local physics = require(“physics”)
physics.start(“true”)
–physics.setDrawMode(“hybrid”)
–insert dpad img
local up = display.newImageRect( “dpad_up.png”, 83, 83 )
up.x = 42
up.y = 411

local left = display.newImageRect( “dpad_left.png”, 83, 83 )
left.x = 162
left.y = 411

local right = display.newImageRect( “dpad_right.png”, 83, 83 )
right.x = 267
right.y = 411
–make group
local enviroment = display.newGroup()

– insert objects and make physical
local floor =display.newRect(0,350,460,10)
physics.addBody (floor, “static”, { density=0, friction = 0, bounce = 0})
floor.myName = “enviroment”
local left_wall = display.newRect(0, 0, 10, 350 )
physics.addBody (left_wall, “static”)
left_wall.myName = enviroment
local right_wall = display.newRect(310, 0, 10, 350)
physics.addBody (right_wall, “static”)
right_wall.myName = enviroment
local player = display.newRect(13, 340, 10, 10 )
player:setFillColor (123,110,2)
physics.addBody (player, {friction = 0, bounce = 0})
player.myName = “player”
–utilize group
enviroment:insert(left_wall, right_wall, floor)
–collision handling
local collisionText = display.newText(“info”,150,50,native.systemfont,16)

local function colllisionPrelim( event )

if ( event.phase == “began” ) then
collisionText.text = event.object1.myName … " & " … event.object2.myName

end

end

local function moveLeft( event )
if (collisionText.text==“enviroment & player”) then
if (event.phase == “began”) then
player:applyForce (500, 500 player.x, player.y)
end
end
end
Runtime:addEventListener(“collision”, colllisionPrelim)
Runtime:addEventListener(“touch”, moveLeft) [import]uid: 86275 topic_id: 23656 reply_id: 323656[/import]

If it’s supported in the Lua language then you can do it in Corona! [import]uid: 29181 topic_id: 23656 reply_id: 94973[/import]

im getting an .lua:54: ‘)’ expected near ‘player’
err
what am i doing wrong
is nested if possible [import]uid: 86275 topic_id: 23656 reply_id: 94976[/import]

im getting an .lua:54: ‘)’ expected near ‘player’
err
what am i doing wrong
is nested if possible [import]uid: 86275 topic_id: 23656 reply_id: 94977[/import]

your missing a comma after your second 500 [import]uid: 21331 topic_id: 23656 reply_id: 94978[/import]

It should be like this:

player:applyForce (500, 500, player.x, player.y)

It would really help if you could repost your code but put it inside
< code> and < /code> tags (take the space out).

Then we can see the nesting and get a better feel for what you’re doing.

You are missing a comma in this line:

player:applyForce (500, 500 player.x, player.y)  

should be:

player:applyForce (500, 500, player.x, player.y)  

With out that comma the parser expects a closing ) after the 500 “near Player”.

[import]uid: 19626 topic_id: 23656 reply_id: 94983[/import]

guess i need to be clearer with my answers… :wink: [import]uid: 21331 topic_id: 23656 reply_id: 94985[/import]

Naw your answer is perfectly clear. The problem is that we all answered it at the same time. It took me longer than you did, but I had not seen your response while I was writing mine.

[import]uid: 19626 topic_id: 23656 reply_id: 94987[/import]

thanks, I guess its true commas save lives… [import]uid: 86275 topic_id: 23656 reply_id: 94990[/import]

I take it that nested if statements are a go in Lua? I had actually had a problem with that a few weeks ago… [import]uid: 105707 topic_id: 23656 reply_id: 95356[/import]

Yes, you may nest your if statements. [import]uid: 21331 topic_id: 23656 reply_id: 95410[/import]

ok all so i got the nested ifs working. Now Im having trouble moving the character when in the air (lines 65-70,84-91)

[code]display.setStatusBar( display.HiddenStatusBar)
– disp constants
local ww = display.contentWidth
local hh = display.contentHeight
–multitouch
system.activate(“multitouch”)
–physics stuff
local physics = require(“physics”)
physics.start(“true”)
–physics.setDrawMode(“hybrid”)
–insert dpad img
local up = display.newImageRect( “dpad_up.png”, 83, 83 )
up.x = 42
up.y = 411

local left = display.newImageRect( “dpad_left.png”, 83, 83 )
left.x = 162
left.y = 411

local right = display.newImageRect( “dpad_right.png”, 83, 83 )
right.x = 267
right.y = 411
–make group
local enviroment = display.newGroup()

– insert objects and make physical
local floor =display.newRect(0,350,460,10)
physics.addBody (floor, “static”,{ density = 1.4, friction = .9, bounce = 0})
floor.myName = “enviroment”
local left_wall = display.newRect(0, 0, 10, 350 )
physics.addBody (left_wall, “static”, { density = 1.4, bounce=0})
left_wall.myName = “enviroment”
local right_wall = display.newRect(310, 0, 10, 350)
physics.addBody (right_wall, “static”,{ density = 1.4, bounce=0})
right_wall.myName = “enviroment”
local player = display.newRect(ww/2, 340, 10, 10 )
player:setFillColor (123,110,2)
physics.addBody (player,{ density = 1.4, friction = 1, bounce = 0})
player.myName = “player”
–utilize group
enviroment:insert(left_wall, right_wall, floor)
–collision handling
local collisionText = display.newText(“info”,150,50,native.systemfont,16)

local function colllisionPrelim( event )

if ( event.phase == “began” ) then
collisionText.text = event.object1.myName … " & " … event.object2.myName
else
collisionText.text=“info”
end
end
local function moveLeft( event )
player.linearDamping = 0
if (collisionText.text==“enviroment & player”) then
if (event.phase == “began”) then
player:applyLinearImpulse (-2, 0, player.x, player.y)
end
if (event.phase==“ended”) then
player.linearDamping=50
end
end
if (collisionText==“info”) then
if (event.phase==“began”) then
player:applyLinearImpulse (-1, 0, player.x, player.y)
end
if (event.phase==“ended”) then
player.linearDamping=50
end
end
end
local function moveRight( event )
player.linearDamping=0
if (collisionText.text==“enviroment & player”) then
if (event.phase == “began”) then
player:applyLinearImpulse (2, 0, player.x, player.y)
end
if (event.phase==“ended”) then
player.linearDamping=50
end
end
if (collisionText==“info”) then
if (event.phase==“began”) then
player:applyLinearImpulse (1, 0, player.x, player.y)
end
if (event.phase==“ended”) then
player.linearDamping=50
end
end
end
local function jump( event )
player.linearDamping=0
if (collisionText.text==“enviroment & player”) then
if(event.phase==“began”) then
player:applyLinearImpulse (0, -1, player.x, player.y)
end
end
end
local function update( event )
if (physics.start==“true”) then
colllisionPrelim()
moveLeft()
moveRight()
end
end
Runtime:addEventListener(“collision”, colllisionPrelim)
left:addEventListener(“touch”, moveLeft)
right:addEventListener(“touch”,moveRight)
up:addEventListener(“touch”,jump)
Runtime:addEventListener(“enterFrame”,update)
[/code] [import]uid: 86275 topic_id: 23656 reply_id: 96176[/import]