Hi,
Just before I dive in, I’ll make my apologies for unclear phrasing/ asking a dumb question!
So I have this function that gets fired when you “hit” a character. This function does a number of things (including triggering other functions) and I’m expecting these to be handled in the order that I write them within the function. (My only other exposure to programming languages is php and javascript where this is definitely the case).
A rough overview of my function:
in the “began” event.phase:
- fade out the various “hitting” buttons to give visual feedback that these cannot be re-hit until the action is complete
- swap the regular character sprite for the “hit” character animation sprite
- play the “hit” sound
in the “ended” even.phase:
- restore the regular character sprite
- run a few functions that update character health etc.
- fade the buttons back up to full opacity
From an amateur perspective, there’s absolutely no way that the hitting buttons can fade out before the hitting animation has finished running (these actions take place in different phases of the event, after all) however what happens is exactly that. Worse, it seems to be quite inconsistent - and jumpy too sometimes. It looks like it’s working way harder than it should. It’s almost as if Corona tries to do *everything at once*. Sometimes the animation swap doesn’t get triggered. Occasionally the buttons don’t fade back to full opacity.
Is there any way of basically saying “don’t do this next bit until this bit has run?”
Also, while we’re on the subject. Although I disable all other screen inputs during each “hitting” action (I don’t want users to be able to continually hit over and over), Corona seems to “queue up” inputs and then executes them all when my function unpauses everything. Is there a way to say “ignore all inputs while this is happening”?
Again, sorry for the vagueness. My full function is below, although the functions it links to aren’t in this block, all they do is retrieve and/or update data from various Ice tables.
Many many thanks for your help in advance,
Andrew
----- master characterAction function —
[blockcode]
local characterAction = function (actioncode,bonusamount,strengthadjust,willadjust)
local animation = nil
local actiontype = nil
local actionname = nil
local anisound = nil
local soundtype = nil
– what sort of action are we dealing with?
if actioncode <= 4 then
actiontype = “beating”
elseif actioncode >= 5 then
actiontype = “torture”
end
– PUNCHED
if actioncode == 1 then
animation = instance3
actionname = “P”
soundtype = “hit”
– KICKED
elseif actioncode == 2 then
animation = kicked
actionname = “K”
soundtype = “hit”
– OTHER ACTION TYPES (3-8) STILL TO DO
end
return function(event)
if “began” == event.phase then
– fade out all buttons
fadebuttons(actiontype)
– the above function fades out buttons like this: transition.to( submenuBeat, { time=100, delay=0, alpha=0.2 } )
– pause/ freeze interaction with other parts of the game until we’re done
paused = true
animation.isVisible = true
playsound(soundtype)
– ANIMATION SWAP (“instance2” is the cryptically-named default sprite)
instance2:pause()
instance2.isVisible = false
– sets focus on the button for all future events even if finger moved off
display.getCurrentStage():setFocus( event.target )
elseif “ended” == event.phase or event.phase == “cancelled” then
– ANIMATION SWAP
instance2.isVisible = true
animation.isVisible = false
– BONUS FOR NON-CONSECUTIVE ACTION –
– add a bonus damage if the last action was something different to this one
local bonus = 0
local lastaction = health:getlastaction()
if lastaction ~= actionname then
bonus = bonusamount
else
bonus = 0
end
– update last action with this current action
health:updatelastaction(actionname)
– UPDATE WILL AND STRENGTH METERS / LEVELS
health:adjusthealth( “strength”, -(strengthadjust+bonus) )
health:adjusthealth( “will”, -(willadjust+bonus) )
getstrength()
getwill()
– COUNT RUN OF SAME ACTION TYPE
– if this action is in a run of same action types, add 1 to run total
local lastactiontype = health:getlastactiontype()
if lastactiontype == actiontype then
– add to total; no need to update action type
health:addtorun(actiontype)
else
– reset actiontype count; update last action type
health:updatelastactiontype(actiontype)
health:resetrun(actiontype)
end
– FINISH BUTTON FOCUS
– removes focus for button
display.getCurrentStage():setFocus(nil)
– INVOKE COMMAND?
local actionrun = health:getruntotal(actiontype)
if actiontype == “beating” and actionrun >= 6 then
– suggest different approach (function not yet written)
health:resetrun(actiontype)
elseif actiontype == “torture” and actionrun >= 6 then
– called into meeting (function not yet written)
health:resetrun(actiontype)
end
– restart standing animation
instance2:play()
paused = false
– restore buttons
restorebuttons(actiontype)
– above function is basically: transition.to( submenuBeat, { time=100, delay=50, alpha=1 } )
end
end
end
[/blockcode]
[import]uid: 132606 topic_id: 31220 reply_id: 331220[/import]

[import]uid: 52491 topic_id: 31220 reply_id: 124934[/import]