4 Replies Latest reply: Mar 20, 2014 8:25 AM by sinious RSS

    global array variables? , transfer data from one layer expression to another

    zipkiev Community Member

      hi i have arrays in expression, but i have a problem, every time when i move effect point control(i need move it for my task)  array update and erasing, but i need to save data from previous array state

       

       

      i add this expression to text layer on Source text

      //create array

      var arrayX = [];

      var arrayY = [];

      //add data to array

      arrayX.push(12);

      arrayX.push(232);

      arrayX.push(2424);

      arrayY.push(0);

      arrayY.push(322);

      arrayY.push(122);

      text_cur_layer = text.sourceText;

      //final result

      text_cur_layer ="Array_X= "+arrayX.join( ', ' )+"\r"+"      Array_Y= "+arrayY.join( ', ' );

       

       

      expression return 

      in array x must be (12 232 2424)

      in arrayY  must be (0 322 122)

       

       

      so every time when i change state on effect "point control"(slider control and etc) this expression updates and give me always same numbers, from this commands^

      arrayX.push(12);

      arrayX.push(232);

      arrayX.push(2424);

      arrayY.push(0);

      arrayY.push(322);

      arrayY.push(122);

       

       

      it happened because i create array every time with

      var arrayX = [];

      var arrayY = [];

      i think this commands erasing all data from array and create new clean array, so i need some how save previous data...., in AE script i can do that with creation array

      globally for all functions, but don't know how  do this in expression

       

       

       

       

      also i think it can be done with transfer data from array to string and save this string in another layer and then get this data after array creation, but i don't know how i can save array string data and export this string back?

       

       

      example

       

       

      var arrayX = [];

      var arrayY = [];

      //try import previous data back(i don't know how do that, just using standard java code..)

      //and now i need get data from strX strY from save place and chekc it later

      if(strX!=null && strY!=null)

      {

      arrayX=strX.split(',');

      arrayX=strX.split(',');

      }

      //add data to array

      arrayX.push(12);

      arrayX.push(232);

      arrayX.push(2424);

      arrayY.push(0);

      arrayY.push(322);

      arrayY.push(122);

      text_cur_layer = text.sourceText;

      //final result

      text_cur_layer ="Array_X= "+arrayX.join( ', ' )+"\r"+"      Array_Y= "+arrayY.join( ', ' );

      //get data to save

      var strX = arrayX.join(',')

      var strY = arrayY.join(', ');

       

       

      and then i need some how save this strX and  strY  to save place

       

       

       

       

      Sorry for bad English

        • 1. Re: global array variables? , transfer data from one layer expression to another
          Dan Ebberts Community Member

          There's no way for an expression to create data that persists from frame to frame. Your expression can go back in time using valueAtTime() to recalculate previous values, but you can't store them.

           

          Dan

          • 2. Re: global array variables? , transfer data from one layer expression to another
            sinious CommunityMVP

            Is using valueAtTime to get the values in a layer at a specific time the best practice means of a global variable? I'd like to move hundreds of objects to pre-calculated size/scales and I can calculate that all at once while randomizing (the seed) start position of these layers. I just need to continuously make sure they end where I want. Is a global in this way the best practice?

            • 3. Re: global array variables? , transfer data from one layer expression to another
              Dan Ebberts Community Member

              It's not clear from your question if you know this, but valueAtTime() is read-only, you can't use it to set values. Also, an expression can only alter the value of the property hosting the exrpession--it can't affect other properties. So each property you want to control would need its own expression.

               

              Dan

              • 4. Re: global array variables? , transfer data from one layer expression to another
                sinious CommunityMVP

                Thanks for the tip. First to answer you, yes it would be a read-only requirement, but in AE I'm probably way off course on the best way to do what I'd like to.

                 

                Imagine building a brick wall (literally) from the bottom of the screen to the top. I'd like the bricks to start 'pooled' in a few different specific positions far off in the distance. Over time each brick flies toward the screen, building the wall brick by brick from the bottom up.

                 

                I figured to do this, expressions might be able to take some of the pain away. Thinking very linear and probably not very AE-like, I imagined I'd create a multi-dimensional array containing the starting and ending positions of every brick. As each frame ticks away I'd run the same expression on every brick, using layer number and 'time' as the only unique things I can use to control the order in which bricks move. So I would need continual read-only access to that multi-dimensional array on every frame.

                 

                I'm probably going about this entirely wrong however. Since I'd need to actually make every single brick layer manually (silly), perhaps what I'm looking for is to be pointed away from expressions and to the AE JavaScript API. Does this sound like a job much better suited to that? I know expressions can't generate layers so for that reason alone it seems like AE JS API is the way to go. If so, what are some good resources for this? I see one on wikia but it's not very reference like. I can't seem to locate the AE equivalent of Flash's JSFL API. I found the PDF version for CS6 but I'd really like the online resource, more reference like so you can click methods/properties/etc for more information rather than one gigantic static page. 

                 

                Thanks for any tips! (BTW I do have Trapcode Echospace. It's great but I find organic looking "randomized" animation a bit difficult with it. It's great if everything is uniform, which isn't what I'm looking for.)