Creative Communities of the World Forums

The peer to peer support community for media production professionals.

  • Posted by Stephen Botting on June 10, 2008 at 9:15 pm

    Hi there,

    I’m getting a result I don’t understand and I’m looking to see if anyone can help.

    I have a text layer with an Expression Slider effect on it named “CurrentCell”. The slider has hold keyframes values of 5,9,13…

    In the Source Text property of the text layer I have the following code:

    vars =
    “13,-1,13,13,L,NW, ,14,L,SW, ,14,L,E, ,14,L,N, ,14,L, , “.split(“,”);
    TargetCell = effect(“CurrentCell”)(“Slider”);
    temp = vars[TargetCell]

    (The spaces are meant to be there, place holders for values not in use in this instance)
    With CurrentCell at a starting value of 5 the result should be NW, but the result I’m getting is “undefined”, once the slider changes to 9 I get the expected result of SW. If I hard code the 5 “temp = vars[5]” I get the expected NW.

    Can anyone explain why I’m getting these strange results?
    It is very frustrating as the code makes sence to me, but the result dont.

    Thanks,
    Stephen

    Stephen Botting replied 17 years, 11 months ago 3 Members · 7 Replies
  • 7 Replies
  • Stephen Botting

    June 10, 2008 at 9:34 pm

    Ok, Sorry to reply to myself, but after sending I had an idea, but I would still like to understand why I’m getting the result I’m getting.

    vars =
    “13,-1,13,13,L,NW, ,14,L,SW, ,14,L,E, ,14,L,N, ,14,L, , “.split(“,”);
    TargetCell = effect(“CurrentCell”)(“Slider”);
    temp = vars[Math.floor(TargetCell)]

    If I floor TargetCell before using TargetCell I get the correct result,

    Stephen Botting

    stephen@43south.co.nz
    https://www.43south.co.nz

  • Filip Vandueren

    June 10, 2008 at 9:46 pm

    It’s funny, but expressions sometimes ‘cast’ values in different roles, sometimes they don’t.

    To retrieve the nth value in a list, you have to be sure N is an integer. Math.floor will absolutely return an integer.
    While the number 5.0 might, because of some weird rounding errors in AE, be interpreted as a float number.

    no better explanation, sorry…

  • Dan Ebberts

    June 10, 2008 at 9:59 pm

    You might want to consider Math.round() instead of Math.floor() because a slider value that displays as 5.0, for example, might really be 4.99999… internally.

    Dan

  • Stephen Botting

    June 11, 2008 at 8:42 pm

    Thanks for the help guys, makes sense now, I think I must have suspected something like that to try floor, but supprised to find it here.

    This reminds me of this fun little trick that used to work in the MacOS calculator, however it still works in AE.

    Create a text layer and place the following code in the source text property.

    t = 1 – 0.9;
    t = t – 0.1;
    t

    It only works with 0.9 first.

    Thanks,
    Stephen

    Stephen Botting

    stephen@43south.co.nz
    https://www.43south.co.nz

  • Stephen Botting

    June 11, 2008 at 8:43 pm

    Thanks for the help guys, makes sense now, I think I must have suspected something like that to try floor, but supprised to find it here.

    This reminds me of this fun little trick that used to work in the MacOS calculator, however it still works in AE.

    Create a text layer and place the following code in the source text property.

    t = 1 – 0.9;
    t = t – 0.1;
    t

    It only works with 0.9 first.

    Thanks,
    Stephen

    Stephen Botting

    stephen@43south.co.nz
    https://www.43south.co.nz

  • Stephen Botting

    June 11, 2008 at 8:43 pm

    Thanks for the help guys, makes sense now, I think I must have suspected something like that to try floor, but supprised to find it here.

    This reminds me of this fun little trick that used to work in the MacOS calculator, however it still works in AE.

    Create a text layer and place the following code in the source text property.

    t = 1 – 0.9;
    t = t – 0.1;
    t

    It only works with 0.9 first.

    Thanks,
    Stephen

    Stephen Botting

    stephen@43south.co.nz
    https://www.43south.co.nz

  • Stephen Botting

    June 11, 2008 at 8:46 pm

    Thanks for the help guys, makes sense now, I think I must have suspected something like that to try floor, but supprised to find it here.

    This reminds me of this fun little trick that used to work in the MacOS calculator, however it still works in AE.

    Create a text layer and place the following code in the source text property.

    t = 1 – 0.9;
    t = t – 0.1;
    t

    It only works with 0.9 first.

    Thanks,
    Stephen

    Stephen Botting

    stephen@43south.co.nz
    https://www.43south.co.nz

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy