If Then Statements / Director Class

I have created two buttons Path One and Path Two and have now made them global variables

_G.pathOne

_G.pathTwo

I have set these buttons on scene One and now need to activate them on scene 5. How do I activate them in the code below that I have for Scene 5? If Path One the scene would go to Scene6a. If pathTwo the scene would go to Scene6. The other Global variable that is down there must stay because it is for something else. I just don’t know how to split if I’m dealing with two scenes using the if and else if statements properly.

[lua] local function touchedSmallbrain (event)
if (“ended” == event.phase) then
_G.numberEight = numberFieldEight.text
director:changeScene (“screen6”)
media.playEventSound( “click_x.caf” )

end
end

smallbrain:addEventListener (“touch”, touchedSmallbrain)
[import]uid: 72372 topic_id: 14012 reply_id: 314012[/import]

say you have _G.onevariable = true in main.lua
in level1.lua you can do something and make this variable false
then, for it to mean something you can write in a function like that:
if _G.onevariable == false then
go to next level
elseif _G.onevariable == true then
stay here
something like that, its pretty hard to explain without actual code) [import]uid: 16142 topic_id: 14012 reply_id: 51606[/import]

Okay I don’t really understand that the true and false. Like I said I have the global variable identified and I show the code where I know the if then statement goes but I don’t know how to put the proper code in to activate it down the line. Also in my main my global is a = 0

Not sure what else you would need to see but if it’s different code let me know I’ll post it. But it’s just two different buttons on one scene and I want to [import]uid: 72372 topic_id: 14012 reply_id: 51611[/import]

if you can post all your code and i will try to help you [import]uid: 16142 topic_id: 14012 reply_id: 51621[/import]

Okay no problem

Screen 1

[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file


local ui = require(“ui”)
local screen3 = display.newImage (“screen3.png”)
localGroup:insert(screen3)
–> This sets Screen2

local optimistic = display.newImage (“optimistic.png”)
optimistic.x = 100
optimistic.y = 385
optimistic.xScale = .5
optimistic.yScale = .5
localGroup:insert(optimistic)
local function touchedOptimistic (event)
if (“ended” == event.phase) then
director:changeScene (“screen4a”)
media.playEventSound( “click_x.caf” )
end
end

optimistic:addEventListener (“touch”, touchedOptimistic)
–>This places the optimistic button

local skeptical = display.newImage (“skeptical.png”)
skeptical.x = 230
skeptical.y = 385
skeptical.xScale = .5
skeptical.yScale = .5
localGroup:insert(skeptical)

local function touchedSkeptical (event)
if (“ended” == event.phase) then
director:changeScene (“screen4”)
media.playEventSound( “click_x.caf” )
end
end

skeptical:addEventListener (“touch”, touchedSkeptical)
–>This places the skeptical button

–>MUST return a display.newGroup()


–> This is how we end every file except for director and main, as mentioned in my first comment

return localGroup

end[/lua]

This is the screen I’m trying to make the split on next

[lua]module(…, package.seeall)

function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file


local ui = require(“ui”)
– Predefine local objects for use later
local numberFieldSeven, numberFieldEight
local fields = display.newGroup()
local inputFontSize = 30
local inputFontHeight = 30
local tHeight = 50

local screen5 = display.newImage (“screen5.png”)
localGroup:insert(screen5)
–> This sets Screen5

local smallbrain = display.newImage (“smallbrain.png”)
smallbrain.x = 270
smallbrain.y = 430
smallbrain.xScale = .5
smallbrain.yScale = .5
localGroup:insert(smallbrain)
–>This places the brain

local function touchedSmallbrain (event)
if (“ended” == event.phase) then
_G.numberEight = numberFieldEight.text
director:changeScene (“screen6”)
media.playEventSound( “click_x.caf” )

end
end

smallbrain:addEventListener (“touch”, touchedSmallbrain)
– Tapping screen dismisses the keyboard
local listener = function( event )
– Hide keyboard
print(“tap pressed”)
native.setKeyboardFocus( nil )
end
Runtime:addEventListener( “tap”, listener )

– This cleanUp function will remove all listeners from the scene since
– Director can’t remove listeners itself

local cleanUp = function()
Runtime:removeEventListener(“tap”, listener)
smallbrain:removeEventListener(“touch”, touchedSmallbrain)
end
– Determine if running on Corona Simulator – Native Text Fields not supported on Simulator
local isSimulator = “simulator” == system.getInfo(“environment”)
if isSimulator then
msg = display.newText( “Native Text Fields not supported on Simulator!”, 0, 280, nil, 12 )
msg.x = display.contentWidth/2 – center title
msg:setTextColor( 255,255,0 )
end
numberFieldSeven = native.newTextField( 50, 80, 85, tHeight, onnumberFieldSeven )
numberFieldSeven.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldSeven.inputType = “number”
numberFieldSeven.align = “center”
numberFieldSeven.text = _G.numberOne

numberFieldEight = native.newTextField( 180, 80, 85, tHeight, onnumberFieldEight )
numberFieldEight.font = native.newFont( native.systemFontBold, inputFontSize )
numberFieldEight.align = “center”
numberFieldEight.inputType = “number”
– Add fields to our new group

localGroup:insert(numberFieldSeven)
localGroup:insert(numberFieldEight)
–>MUST return a display.newGroup()


–> This is how we end every file except for director and main, as mentioned in my first comment

return localGroup

end[/lua] [import]uid: 72372 topic_id: 14012 reply_id: 51626[/import]

[lua]local function touchedSmallbrain (event)
if (“ended” == event.phase) then
_G.numberEight = numberFieldEight.text
director:changeScene (“screen6”)
media.playEventSound( “click_x.caf” )
elseif _G.pathOne == true then
director:changeScene(“screen6a”)
elseif _G.pathTwo == true then
director:changeScene(“screen6”)
end
end[/lua]

this is what you need? you just need to change your variable by external function or whatever and than this function will execute according to values of those two variables
[import]uid: 16142 topic_id: 14012 reply_id: 51636[/import]

Thank you! I’ll try it… [import]uid: 72372 topic_id: 14012 reply_id: 51652[/import]

This worked but I only need one of the elseif at the bottom since I took care of one in the normal screen change.

Thank you! [import]uid: 72372 topic_id: 14012 reply_id: 51752[/import]