Problem repeat function

I need help with the following code.
What I get is that the function is executed repeatedly LOGIC. That is, the first achievement run, however, if I want to run it, how I do it?

[lua]local function combA ()

print(“combA)

end

local function combB ()

print (“combB”)

end

local function combC ()

print (“combC”)

end

local function logic ()

combinacion = math.random (2)
print(“combinacion”)
print(combinacion)
if combinacion == 1 then
timer.performWithDelay(1,combA, 1)
elseif combinacion == 2 then
timer.performWithDelay(1,combB, 1)
elseif combinacion == 3 then
timer.performWithDelay(1,combC, 1)
end

end

logic()[/lua] [import]uid: 98258 topic_id: 34244 reply_id: 334244[/import]

[lua]local function combA ()

print(“combA”)

end

local function combB ()

print (“combB”)

end

local function combC ()

print (“combC”)

end

local function logic ()

combinacion = math.random (2)
print(“combinacion”)
print(combinacion)
if combinacion == 1 then
timer.performWithDelay(1,combA, 1)
elseif combinacion == 2 then
timer.performWithDelay(1,combB, 1)
elseif combinacion == 3 then
timer.performWithDelay(1,combC, 1)
end

end

logic()[/lua] [import]uid: 98258 topic_id: 34244 reply_id: 136144[/import]

First, I’m not sure why you’re using timers. Secondly, combinacion will never be 3 since you’re only returning either a 1 or 2.

I would rewrite logic() like this:

local function logic ()  
 combinacion = math.random (2)  
 print("combinacion", combinacion)  
 if combinacion == 1 then  
 combA()  
 elseif combinacion == 2 then  
 combB()   
 elseif combinacion == 3 then  
 combC()  
 end  
end  

and you should get in a habit of doing:

math.randomseed( os.time() )  

at the beginning of the program to make sure the random number is seeded properly. This is likely the reason you’re getting the same number each time you start the app.
[import]uid: 199310 topic_id: 34244 reply_id: 136149[/import]

I think I explained very well. Excuse me.
What I do is run once this random, can re-run the same function (LOGIC) [import]uid: 98258 topic_id: 34244 reply_id: 136153[/import]

for example, if I put logic() in combA, does not execute the function [import]uid: 98258 topic_id: 34244 reply_id: 136154[/import]

You mean this doesn’t work:

local function combA()  
 logic()  
end  
  
local function logic()  
 ...  
end  

???

That doesn’t work because of something called “forward declaration”. Corona doesn’t know what “logic” is inside of combA() since it hasn’t been defined yet. You can do this:

local logic -- just define the variable here.  
  
local function combA()  
 logic()  
end  
  
logic = function logic() -- you have to use this different syntax for the function.  
 ...  
end  

[import]uid: 199310 topic_id: 34244 reply_id: 136157[/import]

I tried to test and I get the following error:
Syntax error: /Desktop main.lua:476: unexpected symbol near ‘=’
The line 476 is : logic = function logic()

Any suggestions? [import]uid: 98258 topic_id: 34244 reply_id: 136260[/import]

Sorry about that… Typo on my part:

logic = function() [import]uid: 199310 topic_id: 34244 reply_id: 136285[/import]

[lua]local function combA ()

print(“combA”)

end

local function combB ()

print (“combB”)

end

local function combC ()

print (“combC”)

end

local function logic ()

combinacion = math.random (2)
print(“combinacion”)
print(combinacion)
if combinacion == 1 then
timer.performWithDelay(1,combA, 1)
elseif combinacion == 2 then
timer.performWithDelay(1,combB, 1)
elseif combinacion == 3 then
timer.performWithDelay(1,combC, 1)
end

end

logic()[/lua] [import]uid: 98258 topic_id: 34244 reply_id: 136144[/import]

First, I’m not sure why you’re using timers. Secondly, combinacion will never be 3 since you’re only returning either a 1 or 2.

I would rewrite logic() like this:

local function logic ()  
 combinacion = math.random (2)  
 print("combinacion", combinacion)  
 if combinacion == 1 then  
 combA()  
 elseif combinacion == 2 then  
 combB()   
 elseif combinacion == 3 then  
 combC()  
 end  
end  

and you should get in a habit of doing:

math.randomseed( os.time() )  

at the beginning of the program to make sure the random number is seeded properly. This is likely the reason you’re getting the same number each time you start the app.
[import]uid: 199310 topic_id: 34244 reply_id: 136149[/import]

I think I explained very well. Excuse me.
What I do is run once this random, can re-run the same function (LOGIC) [import]uid: 98258 topic_id: 34244 reply_id: 136153[/import]

for example, if I put logic() in combA, does not execute the function [import]uid: 98258 topic_id: 34244 reply_id: 136154[/import]

You mean this doesn’t work:

local function combA()  
 logic()  
end  
  
local function logic()  
 ...  
end  

???

That doesn’t work because of something called “forward declaration”. Corona doesn’t know what “logic” is inside of combA() since it hasn’t been defined yet. You can do this:

local logic -- just define the variable here.  
  
local function combA()  
 logic()  
end  
  
logic = function logic() -- you have to use this different syntax for the function.  
 ...  
end  

[import]uid: 199310 topic_id: 34244 reply_id: 136157[/import]

I tried to test and I get the following error:
Syntax error: /Desktop main.lua:476: unexpected symbol near ‘=’
The line 476 is : logic = function logic()

Any suggestions? [import]uid: 98258 topic_id: 34244 reply_id: 136260[/import]

Sorry about that… Typo on my part:

logic = function() [import]uid: 199310 topic_id: 34244 reply_id: 136285[/import]