Two timers/animations interfering with each other

I have two “downtime” animations that I have going while you play.

  1. the crates in the level will randomly spin.
  2. the main character (hero) will be do something if you wait long enough (like Sonic the Hedgehog does).

I made a timer to stop the hero from moving after a few seconds. The timer works, but his stop animation (“heroleft” or “heroright”) doesn’t play until a crate animation is triggered. For example, hero will scratch like expected, but then get stuck on the last scratch sprite until a crate starts spinning. I can’t for the life of me figure out why these two things are intertwined.

[lua]local function cratespinner()
math.randomseed( os.time() )
cratespindelay = math.random(3,8)
if #pulleycratespawns > 0 then
math.randomseed( os.time() )
local randnum = math.random(#pulleycratespawns)
pulleycratespawns[randnum]:prepare(“crateanimation”)
pulleycratespawns[randnum]:play(“crateanimation”)
end
local function cratetimerGo()
local cratetimer = timer.performWithDelay(cratespindelay*1000, cratespinner, 1)
end
cratetimerGo()
end
cratespinner()
local function herospinner()
math.randomseed( os.time() )
herospindelay = math.random(8,15)
math.randomseed( os.time() )
local randnum = math.random(2)
local isspinning = 0
isspinning = 1
if isanimated == 0 then
local function endspin()
if isspinning == 1 then
if herofacing == 1 then
hero:prepare(“heroleft”)
else
hero:prepare(“heroright”)
end
end
isanimated = 0
isspinning = 0
end
local herospinendtimer = timer.performWithDelay(1000, endspin, 1)
isanimated = 1
if herofacing == 1 then
if randnum == 1 then
hero:prepare(“heroscratchleft”)
hero:play(“heroscratchleft”)
else
hero:prepare(“heropruneleft”)
hero:play(“heropruneleft”)
end
else
if randnum == 1 then
hero:prepare(“heroscratchright”)
hero:play(“heroscratchright”)
else
hero:prepare(“heropruneright”)
hero:play(“heropruneright”)
end
end

end
local function herotimerGo()
local herospintimer = timer.performWithDelay(herospindelay*1000, herospinner, 1)
end
herotimerGo()
end
local herospinstarttimer = timer.performWithDelay(8000, herospinner, 1)

Thanks for your help.
dF [import]uid: 117490 topic_id: 23160 reply_id: 323160[/import]

If I remove the crate section completely,
then hero gets stuck on the last frame of animation indefinitely.
If I put a print(“error”) statement right by hero:prepare(“heroright”), then I get the error statement but “heroright” does not prepare.
Lastly, if I put hero:play(“heroright”) immediately after prepare, I get a slight delay and then it plays. [import]uid: 117490 topic_id: 23160 reply_id: 92647[/import]