lua - Coroutine problems -


so i'm trying make basic gui animation system in roblox, using individual frames , loop put them imagelabel.

this function:

local playanimation = coroutine.create(function(anim,pos,tank)     while true     local animbase = sp.animbase:clone()     animbase.parent = tank     animbase.visible = true     animbase.position = pos -- line causes error mentioned below.     local frame = 1     = 0, animations[anim]["framenum"]         frame = frame + 1         animbase.image = animations[anim]["frames"][frame]         newwait(.1) --this right here, wait, interfears yield.         if frame >= animations[anim]["framenum"]             pos,anim,tank = coroutine.yield()             break         end     end     animbase:destroy()     end end) 

there 2 main problems this: every time runs, error:

20:41:01.934 - players.player1.playergui.screengui.gui-main:65: bad argument #3 'position' (udim2 expected, got number) 

although error doesn't seem anything. (eg. stop script completely)

the line causing error marked comment.

i've made sure pos correct. tried printing before setting it, prints correct thing is: {0,120},{0,65}

the other main problem can't resume after using once. can run line multiple times fine:

coroutine.resume(playanimation,"cannon fire",udim2.new(0,120,0,68-25),tank.frame) 

but won't run:

if tank2:findfirstchild("ammo") , istouching(ammoframe,tank2:getchildren()[3])     local lastammopos = ammoframe.position     ammoframe:destroy()     coroutine.resume(playanimation,"explosion",lastammopos-udim2.new(0,25-(ammotypes[type]["size"].x.offset)/2,0,25),tank.frame)     tank2:getchildren()[3]:destroy() end 

yes, if statement working fine. ammoframe destroyed , third child of tank2. coroutine won't resume.

fixed removing coroutine , wrapping loop inside spawn function.

local playanimation = function(anim,pos,tank)     local animbase = sp.animbase:clone()     animbase.parent = tank     animbase.visible = true     animbase.position = pos     local frame = 1     spawn(function()         = 0, animations[anim]["framenum"]             frame = frame + 1             animbase.image = animations[anim]["frames"][frame]             wait(.1) --this right here, wait, interfears yield.             if frame >= animations[anim]["framenum"]                 break             end         end         animbase:destroy()     end) end 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -