if then problem

Good evening

I do not see where is my mistake … my xmiddle variable and ymiddle = nil, but I do not understand why.

Thank you to you for the walkthrough.

  local xbegin=40                   local ybegin=100                   local xend = 80                   local yend = 200                                      if (xend == xbegin)                   then                   local xmiddle = xend                   if (xend ~= xbegin) then                   local xmiddle = (xend-xbegin)\*0.5+xbegin                     end                                      if (yend == ybegin)                   then                   local ymiddle = yend                   end                                      if (yend ~= ybegin)                   then                   local ymiddle = (yend-ybegin)\*0.5+ybegin                   end                   print( xmiddle, ymiddle, event.x, event.y )

Hi @espace3d,

It appears that these variables are not in scope. See the “Scope Rules” section here for some brief examples:

http://docs.coronalabs.com/guide/start/introLua/index.html#scope

Try setting these as upvalues above and then re-assigning them in the if-then statements. That should solve it.

Brent

nice it"s work thanks

local xmiddle= nil local ymiddle =nil local xbegin=40 local ybegin=100 local xend = 80 local yend = 200                                     if (xend == xbegin)                 then                   xmiddle = xend                 else                   xmiddle = (xend-xbegin)\*0.5+xbegin                   end                                      if (yend == ybegin)                   then                   local ymiddle = yend                   end                                      if (yend ~= ybegin)                   then                   ymiddle = (yend-ybegin)\*0.5+ybegin                                      end                     print( xmiddle, ymiddle, yend, ybegin )

Hi @espace3d,

It appears that these variables are not in scope. See the “Scope Rules” section here for some brief examples:

http://docs.coronalabs.com/guide/start/introLua/index.html#scope

Try setting these as upvalues above and then re-assigning them in the if-then statements. That should solve it.

Brent

nice it"s work thanks

local xmiddle= nil local ymiddle =nil local xbegin=40 local ybegin=100 local xend = 80 local yend = 200                                     if (xend == xbegin)                 then                   xmiddle = xend                 else                   xmiddle = (xend-xbegin)\*0.5+xbegin                   end                                      if (yend == ybegin)                   then                   local ymiddle = yend                   end                                      if (yend ~= ybegin)                   then                   ymiddle = (yend-ybegin)\*0.5+ybegin                                      end                     print( xmiddle, ymiddle, yend, ybegin )