Copy link to clipboard
Copied
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.
you could use:
_global.NPCfunction = _parent.function1;
to define _global.NPCfunction assuming _parent.function1 is already defined.
but it would be better to create an NPC class that would contain the functions and variables common to all NPC's. each particular NPC would inherit from that class and could also define additional variables and functions needed for that character and, if needed, override some (or all) NPC variables and methods.
Copy link to clipboard
Copied
you could use:
_global.NPCfunction = _parent.function1;
to define _global.NPCfunction assuming _parent.function1 is already defined.
but it would be better to create an NPC class that would contain the functions and variables common to all NPC's. each particular NPC would inherit from that class and could also define additional variables and functions needed for that character and, if needed, override some (or all) NPC variables and methods.
Copy link to clipboard
Copied
thanks kglad. Will test it soon.
your second piece of advice is good, that's what I already have.
However I still need to reassign a function to global because these functions are unique from NPC's giving you an option, and none will be common to NPCs. also the function needs to be moved to global because my NPC brains are designed to turn off once they have delivered their various chapters of text / questions / options to the global.
I think your response will work perfectly for this so I will test it out soon.
Thanks again
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
worked perfectly! Thanks
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now