pass value to animation end_callback

Questions and information about using Lua scripting with Storyboard

Moderator: jamiev

pass value to animation end_callback

Postby 141619 » Thu Nov 05, 2015 10:13 pm

Hi
I want to pass value to an animation end callback.
My code is:
Code: Select all
function fun_out_complete(printHello)
   if printHello then
       print('hello!')
   end
end
...
   local isPrintHello = true
   local fun_anim_out_id = gre.animation_create(60, false, fun_out_complete(isPrintHello ) )
   local data ={}
   data["key"] = "Layer.control.alpha"
   data["duration"] = 300
   data["offset"] = 0             
   data["from"] = 255
   data["to"] = 0
   gre.animation_add_step(fun_anim_out_id, data)
   gre.animation_trigger(fun_anim_out_id)


If I pass the value, it will go to the callback immediately and does not wait the animation end.
If I change "fun_out_complete(isPrintHello )" to "fun_out_complete" . It works normal.

Is this a bug ??
141619
 
Posts: 16
Joined: Sun Apr 26, 2015 7:33 pm

Re: pass value to animation end_callback

Postby JohnW » Tue Aug 23, 2016 7:13 am

Hi there sorry I didn't see your post,
You are not passing a function in this case, you are executing the function and then passing the returned value of it.

In order to do what you are looking to do you would need to make an anonymous function that passes a value into your function.

Code: Select all
function fun_out_complete(printHello)
   if printHello then
       print('hello!')
   end
end
...
   local isPrintHello = true
   local fun_anim_out_id = gre.animation_create(60, false, function() fun_out_complete(isPrintHello ) end )
   local data ={}
   data["key"] = "Layer.control.alpha"
   data["duration"] = 300
   data["offset"] = 0             
   data["from"] = 255
User avatar
JohnW
 
Posts: 56
Joined: Wed May 08, 2013 4:52 pm


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 2 guests

cron