Conditional operator does not work "If - else if - end"

I use “Storyboard”, and conditional operator does not work on the create scene. The file result.lua have this statement, he must rely age depending on the variable mydata.year. But operator "if"does not work.

My code on the zip file “test.zip”.

 Please, help me, what am I doing wrong?

p.s. sorry for my english, I am from Russia.

It looks to me like mydata.year is 0.  If that’s true, your if statement will never pick it up.

Rob

I don’t understand, what am I doing wrong?

What should I do to fix the error?

I don’t understand why operator “if” can’t determine variable mydata.year? On the result.lua

Rob is saying that you initialise mydata.year = 0 in result.lua, so even if you set mydata.year to something else in the test.lua scene, as soon as you return to result.lua this is overwritten.

You could also do with looking into tables, loops and using parameters for IDs etc. For example, this code in test1.lua would do the same job, but saves hundreds of lines and is far easier to edit - say if you decide you don’t like their X position or want to move them closer together.

I can’t test it as I’m not at my dev machine but you get the idea…

[lua]

local textFields = {}

local text = {}

mydata.five = {}

local yGap = 50

local userInput = function (event)  – put this function somewhere above createScene

      local id = event.target.id

      if (event.phase == “ended” or event.phase == “submitted”) then

                  native.setKeyboardFocus( nil )

                  mydata.five[id] = event.target.text

    end

end

for a = 1 , 23 , 1 do           – put this code in createScene

      local txt = 1 +( (a- 1 ) \ *5 ) …” -“. .5 +((a- 1 )\ *5 )

      local py = Y/ 2 + 150 + (yGap * a)

      local t = display.newText(txt, X/ 2 - 85 , py, Arial, 33 )

      t:setFillColor( 0 )

      scrollView:insert(t)

      text[a] = t

      local tf = native.newTextField(X/ 2 + 70 , py, 150 , 33 )

      tf.inputType = “number”

      tf.size = 20

      tf.alpha = 0

      tf.id = a

      scrollView:insert(tf)

      transition.to(tf, {time = 1500 , alpha = 1 })

      textFields[a] = tf

end

[/lua]

It looks to me like mydata.year is 0.  If that’s true, your if statement will never pick it up.

Rob

I don’t understand, what am I doing wrong?

What should I do to fix the error?

I don’t understand why operator “if” can’t determine variable mydata.year? On the result.lua

Rob is saying that you initialise mydata.year = 0 in result.lua, so even if you set mydata.year to something else in the test.lua scene, as soon as you return to result.lua this is overwritten.

You could also do with looking into tables, loops and using parameters for IDs etc. For example, this code in test1.lua would do the same job, but saves hundreds of lines and is far easier to edit - say if you decide you don’t like their X position or want to move them closer together.

I can’t test it as I’m not at my dev machine but you get the idea…

[lua]

local textFields = {}

local text = {}

mydata.five = {}

local yGap = 50

local userInput = function (event)  – put this function somewhere above createScene

      local id = event.target.id

      if (event.phase == “ended” or event.phase == “submitted”) then

                  native.setKeyboardFocus( nil )

                  mydata.five[id] = event.target.text

    end

end

for a = 1 , 23 , 1 do           – put this code in createScene

      local txt = 1 +( (a- 1 ) \ *5 ) …” -“. .5 +((a- 1 )\ *5 )

      local py = Y/ 2 + 150 + (yGap * a)

      local t = display.newText(txt, X/ 2 - 85 , py, Arial, 33 )

      t:setFillColor( 0 )

      scrollView:insert(t)

      text[a] = t

      local tf = native.newTextField(X/ 2 + 70 , py, 150 , 33 )

      tf.inputType = “number”

      tf.size = 20

      tf.alpha = 0

      tf.id = a

      scrollView:insert(tf)

      transition.to(tf, {time = 1500 , alpha = 1 })

      textFields[a] = tf

end

[/lua]