Page 1 of 1

Trying to use hump.tween to tween arrays... without success.

Posted: Mon Jul 06, 2015 1:22 pm
by nibylev
Hi,
does anyone know if thats possible to tween arrays?
I have an obejct "a" of class Foo. I set some table in it:

Code: Select all

a.table = {1, 2, 3}
then I try to tween it:

Code: Select all

  fg.timer:tween(1,a, {table[1] =3)
but I get an error. Also tweenging the wole table does not work:

Code: Select all

[code]  fg.timer:tween(1,a, {table = {3, 3, 3})
[/code]
Please help!

Re: Trying to use hump.tween to tween arrays... without succ

Posted: Mon Jul 06, 2015 1:33 pm
by s-ol

Code: Select all

fg.timer:tween(1,a, {table[1] = 3})
would mean "tween the key table[1] (which is nil) to a value of 3", so nothing happens. You want:

Code: Select all

fg.timer:tween(1,a.table, {[1] = 3})
or if you want to keep the "nested" table tween:

Code: Select all

fg.timer:tween(1,a, { table = {3} })

Re: Trying to use hump.tween to tween arrays... without succ

Posted: Mon Jul 06, 2015 4:33 pm
by nibylev
Thanks, although I don't get one thing: the value a.table[1] is not nil, so I would expect my code to work. How do you mean that value is nil?

Re: Trying to use hump.tween to tween arrays... without succ

Posted: Mon Jul 06, 2015 9:00 pm
by s-ol
nibylev wrote:Thanks, although I don't get one thing: the value a.table[1] is not nil, so I would expect my code to work. How do you mean that value is nil?
a.table[1] is not nil, but table[1] is.

Re: Trying to use hump.tween to tween arrays... without succ

Posted: Mon Jul 06, 2015 9:00 pm
by s-ol
nibylev wrote:Thanks, although I don't get one thing: the value a.table[1] is not nil, so I would expect my code to work. How do you mean that value is nil?
a.table[1] is not nil, but table[1] is nil (table is a global variable that contains helper functions, but not the key 1)

Re: Trying to use hump.tween to tween arrays... without succ

Posted: Tue Jul 07, 2015 12:17 am
by nibylev
So what is the syntax of timer:tween? The documentation suggests that the code

Code: Select all

fg.timer:tween(time, object, {param = value})
tweens object.param from current value to value specified in {}. What is that thing I am missing?

Re: Trying to use hump.tween to tween arrays... without succ

Posted: Tue Jul 07, 2015 1:38 am
by s-ol
nibylev wrote:So what is the syntax of timer:tween? The documentation suggests that the code

Code: Select all

fg.timer:tween(time, object, {param = value})
tweens object.param from current value to value specified in {}. What is that thing I am missing?
you cannot have a key like "subvalue[value]" or "key.key". The third argument is just a lua table itself. To access a nested property you have to give it a nested "target table", as seen in the documentation aswell.

for example consider a setup like this:

Code: Select all

tweenme = {}
tweenme.table = {a=3}
tweenme["table.a"] = 3

fg.timer:tween(1, tweenme, {table = {a=2}}) -- will tween the first value
fg.timer:tween(1, tweenme, {["table.a"] = 2}) -- will tween the second value

Re: Trying to use hump.tween to tween arrays... without succ

Posted: Wed Jul 08, 2015 9:35 am
by nibylev
Thanks for replies, I understood some. :)
I will be investigating this from side of lua syntax later. This is completely new language for me.