Hello, everyone. I’m hoping someone can suggest a remedy for this morning’s Frustration of the Day…hehe
I’m making a card game. After you make a match, the cards on the table move to new positions. I’m doing this in a function called move_field(), which pretty much sets up the transitions (in addition to some other minor setup things). What I’d like to do is not return from this function until all those transitions are complete.
My idea made sense to me: I’ll make a count of the current transitions. When a transition is complete, I’ll decrease the count by 1…and when the count is finally 0, return from move_field(). Unfortunately, everything I try simply hangs the Simulator, and I must force quit.
I’ve tried making a wait() function, I’ve tried re-cursively running a function until completion…
Here’s a sample of the code…I think it includes everything you’d need. Please let me know if there’s anything else you need, and I am immensely thankful in advance for any help on the subject.
transition\_count = 0
local function transition\_done()
transition\_count = transition\_count - 1
end
local function move\_field(num)
transition\_count = #field\_cards - num
for i = num+1, #field\_cards do
local card = cardArray[field\_cards[i]]
if card.row == 1 then
transition.to(card, { delta = true, x = -x\_offset, y = y\_offset, onComplete = transition\_done })
else
transition.to(card, { delta = true, y = -y\_offset, onComplete = transition\_done })
end
card.row = math.abs(card.row - 3); card.in\_field = card.in\_field - 1
end
-- Don't return until the transitions are finished.
end
[import]uid: 21712 topic_id: 7152 reply_id: 307152[/import]