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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
nibylev
Prole
Posts: 5
Joined: Mon Jul 06, 2015 1:16 pm

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

Post 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!
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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} })

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
nibylev
Prole
Posts: 5
Joined: Mon Jul 06, 2015 1:16 pm

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

Post 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?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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)

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
nibylev
Prole
Posts: 5
Joined: Mon Jul 06, 2015 1:16 pm

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

Post 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?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
nibylev
Prole
Posts: 5
Joined: Mon Jul 06, 2015 1:16 pm

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

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests