creating lots of helpfull functions? - Printable Version +- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum) +-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html) +--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html) +--- Thread: creating lots of helpfull functions? (/thread-4514.html) |
creating lots of helpfull functions? - gosseyn - 09-18-2010 hello, I want to create pre-made functions that i will use again and again inside my script file. For example, i want to create the function WaitOneSec(which will obviously permit me to place a timer of 1 second wherever i want), and then WaitTwoSec, WaitThreeSec etc.. The problem is that i am not sure how to put it, because AddTimer demands a function as parameter. Should i do it like that : Code: void WaitOneSec(string& asFunction) and then in my main code, whenever i want to add a timer before a function, i would do the following(for example wait 1 sec then kill player) : Code: WaitOneSec("KillPlayer"); This is assuming 1.0f is equal to one second. What do you think ? EDit : Also, is it possible to insert a function inside another function as parameter with this scripting language, like this : Code: AddEntityCollideCallback("Player", "AreaChairFly", AddPropImpulse("MyChair", 0.0, 7, 0.0, "world"), false, 0); Thanks! RE: creating lots of helpfull functions? - Luis - 09-18-2010 (09-18-2010, 07:57 AM)gosseyn Wrote: hello, This would indeed work. (09-18-2010, 07:57 AM)gosseyn Wrote: EDit :Nope, this wouldn't work, cos the AddEntityCollideCallback expects a collide callback function name only (meaning a function with 3 parameters - String parent_name, String child_name, int state_of_collision). You can always create a function that works just like an alias for that call, like: Code: AddEntityCollideCallback("Player", "AreaChairFly", "CollideWithAreaChairFly", false, 0); (09-18-2010, 07:57 AM)gosseyn Wrote: Thanks! You're welcome RE: creating lots of helpfull functions? - Deruu - 09-18-2010 (09-18-2010, 09:51 AM)Luis Wrote: Nope, this wouldn't work, cos the AddEntityCollideCallback expects a collide callback function name only (meaning a function with 3 parameters - String parent_name, String child_name, int state_of_collision). You can always create a function that works just like an alias for that call, like: I do believe he wants anonymous functions, which would be very convenient. I'm not too familiar with AngelScript, but from what I could gather it doesn't seem to support anonymous functions. |