5 Replies Latest reply on Aug 14, 2013 6:31 AM by kglad

    Copy one function's statements in to another

    sabooru Level 1

      Hi there I am using AS2.0 from an older project as the process to transform it to AS3 would be too overwhelming for me.

       

      I want to know...

      Is it possible to copy one functions statements in to another different function.

       

      I have thought about using global vars and will do that if I need to but this would be much more convenient if possible for the application.

       

      The reason - I am making a game.

      I have an NPC that carries its own variables declared on load, when the player talks the NPC it passes the variables to the _root, allowing the text-window to display the message/discussion from said NPC.

       

      I am using one main 'npc-brain' so that when it is dragged in to the stage, the same actions and code are run for each NPC, and the variables can be modified by grabbing them from the NPC's _parent - this allows instances of the same MC modified by just changing variables on the _parent.

       

      This works fine but I now also want NPCs to trigger their own functions.

       

      I want NPC's to carry functions that are declared on load, just like the variables, and when the right parameters are met, add that function to the root so that it can be declared separately form the NPC brain when parameters are activated from the separate textbox/discussion MC.

       

      I have a few other ideas but this would be the most convenient.

       

      hoping to create something that would work like this:

       

       

      _global.NPCfunction = function (){} = _parent.function1(){ trace ("blabla")};

       

       

      /* global NPC function takes on all the statements from the MC's parent function, it will trace blabla */

       

       

      Really just need to know if its possible to copy all the statements of one function in to another function on a different level. If not I should be able to pursue the other options on my own. This would just be more convenient for the particular situation as it turns out.

       

      Other things that would solve this well are converting a local function in to a global function / Automatically moving the function to a global level

      Or an ability to create a set of statements that are idle outside of a function, that can be used when the function is called to write the function automatically with variable statements.

       

      Again don't even know if this is possible but it would be very helpful.