Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating lots of helpfull functions?
gosseyn Offline
Member

Posts: 63
Threads: 7
Joined: Sep 2010
Reputation: 1
#1
creating lots of helpfull functions?

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 :

void WaitOneSec(string& asFunction)
{
AddTimer("", 1.0f, 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) :
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 :
AddEntityCollideCallback("Player", "AreaChairFly", AddPropImpulse("MyChair", 0.0, 7, 0.0, "world"), false, 0);

Thanks!
09-18-2010, 07:57 AM
Find
Luis Offline
Frictional Games

Posts: 280
Threads: 19
Joined: Jun 2006
Reputation: 9
#2
RE: creating lots of helpfull functions?

(09-18-2010, 07:57 AM)gosseyn Wrote: 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 :

void WaitOneSec(string& asFunction)
{
AddTimer("", 1.0f, 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) :
WaitOneSec("KillPlayer");

This is assuming 1.0f is equal to one second.

What do you think ?

This would indeed work.

(09-18-2010, 07:57 AM)gosseyn Wrote: EDit :
Also, is it possible to insert a function inside another function as parameter with this scripting language, like this :
AddEntityCollideCallback("Player", "AreaChairFly", AddPropImpulse("MyChair", 0.0, 7, 0.0, "world"), false, 0);
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:

AddEntityCollideCallback("Player", "AreaChairFly", "CollideWithAreaChairFly", false, 0);

...

void CollideWithAreaChairFly(String &in asParent, String &in asChild, int alState)
{
      AddPropImpulse("MyChair", 0.0, 7, 0.0, "world");
}

(09-18-2010, 07:57 AM)gosseyn Wrote: Thanks!

You're welcome Smile

EOF
09-18-2010, 09:51 AM
Find
Deruu Offline
Junior Member

Posts: 6
Threads: 0
Joined: Sep 2010
Reputation: 0
#3
RE: creating lots of helpfull functions?

(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:

AddEntityCollideCallback("Player", "AreaChairFly", "CollideWithAreaChairFly", false, 0);

...

void CollideWithAreaChairFly(String &in asParent, String &in asChild, int alState)
{
      AddPropImpulse("MyChair", 0.0, 7, 0.0, "world");
}

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.
09-18-2010, 10:14 AM
Website Find




Users browsing this thread: 2 Guest(s)