RaideX
Member
Posts: 212
Threads: 33
Joined: May 2013
Reputation:
7
|
Adding Delays
So, hi again people. First of all (as some might have noticed) i got to the scripting section for my coming full conversion. And sadly that's where i'm weakest at.
But i am aware of the basics and can do stuff that i have planned, but for one thing i can't get working without adding too much code.
I think i'll explain it with an example:
I want to execute functionXY with a timer that starts when the player enters a specific area. After the player entered the area, functionXY is going to be excecuted and does thingXY. Now i want that after thingXY happens something else should happen with a delayXY, let's say 1 second.
What i would do is the following:
void OnStart() {
AddTimer ("ExecFunctionXY", 10.0f, "FunctionXY") }
void FunctionXY (string &in asTimer) { thingXY() AddTimer ("FunctionZDelay", 1.0f, "FunctionZDelay") }
void FunctionZDelay (string &in asTimer) { delayedthingZ() }
So basically i'm adding a timer after a certain function has been called to execute something delayed.
Is there a way to code that a bit more "pretty"?
I'm guessing it has to do with parameters, but sadly i'm really not good at this part. Hope you guys can help and hopefully i can learn something new. :3
If you don't draw first, you don't get to draw at all... -The False Shepherd
(This post was last modified: 11-22-2013, 07:14 PM by RaideX.)
|
|
11-22-2013, 07:12 PM |
|
ExpectedIdentifier
Member
Posts: 234
Threads: 10
Joined: Sep 2012
Reputation:
11
|
RE: Adding Delays
(11-22-2013, 07:12 PM)RaideX Wrote: So, hi again people. First of all (as some might have noticed) i got to the scripting section for my coming full conversion. And sadly that's where i'm weakest at.
But i am aware of the basics and can do stuff that i have planned, but for one thing i can't get working without adding too much code.
I think i'll explain it with an example:
I want to execute functionXY with a timer that starts when the player enters a specific area. After the player entered the area, functionXY is going to be excecuted and does thingXY. Now i want that after thingXY happens something else should happen with a delayXY, let's say 1 second.
What i would do is the following:
void OnStart() {
AddTimer ("ExecFunctionXY", 10.0f, "FunctionXY") }
void FunctionXY (string &in asTimer) { thingXY() AddTimer ("FunctionZDelay", 1.0f, "FunctionZDelay") }
void FunctionZDelay (string &in asTimer) { delayedthingZ() }
So basically i'm adding a timer after a certain function has been called to execute something delayed.
Is there a way to code that a bit more "pretty"?
I'm guessing it has to do with parameters, but sadly i'm really not good at this part. Hope you guys can help and hopefully i can learn something new. :3
void OnStart() {
AddTimer ("ExecFunctionXY_1", 10.0f, "FunctionXY") AddTimer ("ExecFunctionXY_2", 11.0f, "FunctionXY") }
void FunctionXY (string &in asTimer) { if(asTimer=="ExecFunctionXY_1") { thingXY() } if(asTimer=="ExecFunctionXY_2") { delayedthingZ() } }
Something like this maybe? It really depends on how many functions you want to use with delays. This is probably the simplest for just a function followed by a delay followed by a function.
Closure ModDB page:
|
|
11-22-2013, 07:50 PM |
|
RaideX
Member
Posts: 212
Threads: 33
Joined: May 2013
Reputation:
7
|
RE: Adding Delays
Quote:void OnStart() {
AddTimer ("ExecFunctionXY_1", 10.0f, "FunctionXY") AddTimer ("ExecFunctionXY_2", 11.0f, "FunctionXY") }
void FunctionXY (string &in asTimer) { if(asTimer=="ExecFunctionXY_1") { thingXY() } if(asTimer=="ExecFunctionXY_2") { delayedthingZ() } }
Something like this maybe? It really depends on how many functions you want to use with delays. This is probably the simplest for just a function followed by a delay followed by a function.
Yeh that should work just fine. Awesome! Thank you for that.
How would it be done with collide areas? (i.e. AddEntityCollideCallback)
In a more specific way i would like to execute the delayed function after the player enters the area (and by that triggers the first function)
Thanks for taking you'r time mate.
If you don't draw first, you don't get to draw at all... -The False Shepherd
(This post was last modified: 11-22-2013, 08:01 PM by RaideX.)
|
|
11-22-2013, 07:58 PM |
|
ExpectedIdentifier
Member
Posts: 234
Threads: 10
Joined: Sep 2012
Reputation:
11
|
RE: Adding Delays
(11-22-2013, 07:58 PM)RaideX Wrote: Quote:void OnStart() {
AddTimer ("ExecFunctionXY_1", 10.0f, "FunctionXY") AddTimer ("ExecFunctionXY_2", 11.0f, "FunctionXY") }
void FunctionXY (string &in asTimer) { if(asTimer=="ExecFunctionXY_1") { thingXY() } if(asTimer=="ExecFunctionXY_2") { delayedthingZ() } }
Something like this maybe? It really depends on how many functions you want to use with delays. This is probably the simplest for just a function followed by a delay followed by a function.
Yeh that should work just fine. Awesome! Thank you for that.
How would i do it with collide areas?
Thanks for taking you'r time mate.
void OnStart() { AddEntityCollideCallback("Player", "CollideArea", "CollideFunction", true, 1); }
void CollideFunction(string &in asParent, string &in asChild, int alState) { AddTimer ("ExecFunctionXY_1", 10.0f, "FunctionXY") AddTimer ("ExecFunctionXY_2", 11.0f, "FunctionXY") }
Something like this?
Closure ModDB page:
|
|
11-22-2013, 08:00 PM |
|
RaideX
Member
Posts: 212
Threads: 33
Joined: May 2013
Reputation:
7
|
RE: Adding Delays
(11-22-2013, 08:00 PM)sonataarctica Wrote: (11-22-2013, 07:58 PM)RaideX Wrote: Quote:void OnStart() {
AddTimer ("ExecFunctionXY_1", 10.0f, "FunctionXY") AddTimer ("ExecFunctionXY_2", 11.0f, "FunctionXY") }
void FunctionXY (string &in asTimer) { if(asTimer=="ExecFunctionXY_1") { thingXY() } if(asTimer=="ExecFunctionXY_2") { delayedthingZ() } }
Something like this maybe? It really depends on how many functions you want to use with delays. This is probably the simplest for just a function followed by a delay followed by a function.
Yeh that should work just fine. Awesome! Thank you for that.
How would i do it with collide areas?
Thanks for taking you'r time mate.
void OnStart() { AddEntityCollideCallback("Player", "CollideArea", "CollideFunction", true, 1); }
void CollideFunction(string &in asParent, string &in asChild, int alState) { AddTimer ("ExecFunctionXY_1", 10.0f, "FunctionXY") AddTimer ("ExecFunctionXY_2", 11.0f, "FunctionXY") }
Something like this?
yeh, that isn't what i excectly searched for but i can make this to do it my way. thanks anyway, you'r great.
EDIT: Just for the curious, i wanted to set it up so when the player enters the area, a certain music stops playing and after the delay timer ended it should excecute a sound at the player (like a scare sound).
If you don't draw first, you don't get to draw at all... -The False Shepherd
(This post was last modified: 11-22-2013, 08:11 PM by RaideX.)
|
|
11-22-2013, 08:07 PM |
|
ExpectedIdentifier
Member
Posts: 234
Threads: 10
Joined: Sep 2012
Reputation:
11
|
RE: Adding Delays
(11-22-2013, 08:07 PM)RaideX Wrote: yeh, that isn't what i excectly searched for but i can make this to do it my way. thanks anyway, you'r great.
Alright, well if you explain what you want I will write it for you :-)
Closure ModDB page:
|
|
11-22-2013, 08:09 PM |
|
RaideX
Member
Posts: 212
Threads: 33
Joined: May 2013
Reputation:
7
|
RE: Adding Delays
added it to the post above c:
If you don't draw first, you don't get to draw at all... -The False Shepherd
|
|
11-22-2013, 08:14 PM |
|
FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
|
RE: Adding Delays
void OnStart()
{
AddTimer ("FunctionXY_1", 10.0f, "FunctionXY")
}
void FunctionXY (string &in asTimer)
{
if(asTimer == "FunctionXY_1")
{
thingXY()
AddTimer ("FunctionXY_2", 1.0f, "FunctionXY ")
}
if(asTimer == "FunctionXY_2")
{
thingZ()
}
}
How does this look to you?
Trying is the first step to success.
|
|
11-23-2013, 01:37 AM |
|
RaideX
Member
Posts: 212
Threads: 33
Joined: May 2013
Reputation:
7
|
RE: Adding Delays
(11-23-2013, 01:37 AM)FlawlessHair Wrote: void OnStart()
{
AddTimer ("FunctionXY_1", 10.0f, "FunctionXY")
}
void FunctionXY (string &in asTimer)
{
if(asTimer == "FunctionXY_1")
{
thingXY()
AddTimer ("FunctionXY_2", 1.0f, "FunctionXY ")
}
if(asTimer == "FunctionXY_2")
{
thingZ()
}
}
How does this look to you?
yes. that seems to be it! probably could've come on that one myselfe, but hey. Thanks for this :3
If you don't draw first, you don't get to draw at all... -The False Shepherd
|
|
11-23-2013, 11:06 AM |
|
FlawlessHappiness
Posting Freak
Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation:
171
|
RE: Adding Delays
Great, no problem
Trying is the first step to success.
|
|
11-23-2013, 12:01 PM |
|
|