1
votes

I'm very confused about the flow of the programs in corona sdk.

What I want to make is that the flow continues when the transition is over, I know I can use Oncomplete but I do not know how to use it in this case.

I have this code:

while ban == 2 do  
    actual = x
    desplazar = x
    while actual >= 0  do 
        actual = actual - 4
        if inTable(t,actual) then
            while inTable(t,actual) and actual >=0 do
                actual= actual - 4
            end
        end       
    if actual >= 0 then
         banaux=1  
         if inTable(t, desplazar) then
             block[desplazar].value=0
             block[desplazar]:removeSelf()
             for z=1, tablelength(t) do
                  if t[z] == desplazar then
                  t[z]=32
             end  
         end  
    end   
    transition.to(block[actual], {time=velocity, x=block[desplazar].x, y=block[desplazar].y})
    cambiodesp(actual,desplazar)
    desplazar = desplazar - 4 
  end        
 end
 x = x -1
 if inTable(t,x) then
 else
    ban = 1    
 end    
end

I'm getting a lot of unexpected result because of the transitions, I supposed that the code keep running although the transition haven't finished, I want to make something for run the above code when the transition is complete, but I think I cannot use the oncomplete.

I want to make keep running when this is complete

transition.to(block[actual], {time=velocity, x=block[desplazar].x, y=block[desplazar].y})

I'm not understanding how the flow of the code is working, so hope you can explain to me that

1

1 Answers

0
votes

Maybe you can use this trick but I don't recommend this. Because it may block run time. I suggest you to write functions. So you can use onComplete method properly

Anyways, here is the bad but quick way to fix it:

while ban == 2 do  
    actual = x
    desplazar = x
    while actual >= 0  do 
        actual = actual - 4
        if inTable(t,actual) then
            while inTable(t,actual) and actual >=0 do
                actual= actual - 4
            end
        end       
    if actual >= 0 then
         banaux=1  
         if inTable(t, desplazar) then
             block[desplazar].value=0
             block[desplazar]:removeSelf()
             for z=1, tablelength(t) do
                  if t[z] == desplazar then
                  t[z]=32
             end  
         end  
    end   
    local isEnded = false
    transition.to(block[actual], {time=velocity, x=block[desplazar].x, y=block[desplazar].y, onComplete = function() isEnded = true end })
    while isEnded == false then end
    cambiodesp(actual,desplazar)
    desplazar = desplazar - 4 
  end        
 end
 x = x -1
 if inTable(t,x) then
 else
    ban = 1    
 end    
end