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
i forgot how to script :c
nightsxp Offline
Member

Posts: 53
Threads: 8
Joined: Sep 2011
Reputation: 0
#1
i forgot how to script :c

Hi all.I forgot how to script Dodgy how can i do this one?:
when player in specific area the screen turning black.then,after 2 seconds will sound play,and after 4 seconds will another sound play.How to teleport player to the next map with script area?I hope you will help Tongue sorry for my baaaaad english. Confused
12-14-2012, 07:51 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#2
RE: i forgot how to script :c

What you want is first a collide script.

Your script should look like this:

void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea_1", "PlaySounds", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_2", "TeleportToNextMap", true, 1);

}

void PlaySounds(string &in asParent, string &in asChild, int alState)
{
FadeOut(0);
AddTimer("Sound_1", 2, "CollideFunctionTimer_1");
AddTimer("Sound_2", 4, "CollideFunctionTimer_1");

}

void CollideFunctionTimer_1(string &in asTimer)
{
if(asTimer == "Sound_1")
{
PlaySoundAtEntity("Sound_1", "[SOUND].snt", "Player", 0, false);
}


if(asTimer == "Sound_2")
{
PlaySoundAtEntity("Sound_2", "[SOUND].snt", "Player", 0, false);
}
}

void TeleportToNextMap(string &in asParent, string &in asChild, int alState)
{
ChangeMap("[MAPNAME].map", "PlayerStartArea_1", "", "");
}

Replace the Bold names with what they need.

Trying is the first step to success.
(This post was last modified: 12-14-2012, 08:11 AM by FlawlessHappiness.)
12-14-2012, 08:11 AM
Find
nightsxp Offline
Member

Posts: 53
Threads: 8
Joined: Sep 2011
Reputation: 0
#3
RE: i forgot how to script :c

(12-14-2012, 08:11 AM)beecake Wrote: What you want is first a collide script.

Your script should look like this:

void OnStart()
{
AddEntityCollideCallback("Player", "ScriptArea_1", "PlaySounds", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_2", "TeleportToNextMap", true, 1);

}

void PlaySounds(string &in asParent, string &in asChild, int alState)
{
FadeOut(0);
AddTimer("Sound_1", 2, "CollideFunctionTimer_1");
AddTimer("Sound_2", 4, "CollideFunctionTimer_1");

}

void CollideFunctionTimer_1(string &in asTimer)
{
if(asTimer == "Sound_1")
{
PlaySoundAtEntity("Sound_1", "[SOUND].snt", "Player", 0, false);
}


if(asTimer == "Sound_2")
{
PlaySoundAtEntity("Sound_2", "[SOUND].snt", "Player", 0, false);
}
}

void TeleportToNextMap(string &in asParent, string &in asChild, int alState)
{
ChangeMap("[MAPNAME].map", "PlayerStartArea_1", "", "");
}

Replace the Bold names with what they need.
Oh.my.god.Thank you a lot!! aand..can you explain what does (string &in asParent, string &in asChild, int alState) mean?
12-14-2012, 08:23 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#4
RE: i forgot how to script :c

This should explain it: http://www.frictionalgames.com/forum/thread-18368.html

Trying is the first step to success.
12-14-2012, 09:12 AM
Find
nightsxp Offline
Member

Posts: 53
Threads: 8
Joined: Sep 2011
Reputation: 0
#5
RE: i forgot how to script :c

(12-14-2012, 09:12 AM)beecake Wrote: This should explain it: http://www.frictionalgames.com/forum/thread-18368.html
Thanks :OO
12-14-2012, 09:53 AM
Find
nightsxp Offline
Member

Posts: 53
Threads: 8
Joined: Sep 2011
Reputation: 0
#6
RE: i forgot how to script :c

And..how to use if(HasItem)?

void lantern(WHAT SHOULD I PLACE IN HERE?)
{
if(HasItem("lantern") == true)
{

SetEntityActive("block", false);}}
12-17-2012, 10:28 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#7
RE: i forgot how to script :c

It depends on what kind of function you are using Wink

You made the callback with AddEntityCollideFuntion, then it's (string &in asParent, string &in asChild, int alState)

If it's an interact-script it's (string &in asEntity)

If it's a script where you use an item it's (string &in asItem, string &in asEntity)

if it's a timer it's (string &in asTimer).

Get it?

Trying is the first step to success.
12-17-2012, 11:32 AM
Find
nightsxp Offline
Member

Posts: 53
Threads: 8
Joined: Sep 2011
Reputation: 0
#8
RE: i forgot how to script :c

(12-17-2012, 11:32 AM)beecake Wrote: It depends on what kind of function you are using Wink

You made the callback with AddEntityCollideFuntion, then it's (string &in asParent, string &in asChild, int alState)

If it's an interact-script it's (string &in asEntity)

If it's a script where you use an item it's (string &in asItem, string &in asEntity)

if it's a timer it's (string &in asTimer).

Get it?
Yes o.o Thank you o.o

what;s wrong??


AddEntityCollideCallback("Player","Area ","lantern");




void gothrough(string &in asParent, string &in asChild, int alState)
{
if(HasItem("lantern") == true)
{

SetEntityActive("block", false);


}


}


i actually want: if player has lantern he can go throuh ''Area''
(This post was last modified: 12-17-2012, 12:51 PM by nightsxp.)
12-17-2012, 12:13 PM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#9
RE: i forgot how to script :c

I'd like to add a few points to what beecake said, just to clarify a few details, so you can get on track faster and make these kinds of decisions yourself.

(12-14-2012, 08:23 AM)nightsxp Wrote: aand..can you explain what does (string &in asParent, string &in asChild, int alState) mean?
As you've seen if you've read beecake's article, that's what's called a parameter list of a function - basically, these are named variables, which are local to the function (not available for use from outside of the function), and which get their values assigned whenever a call to the function is made (by you, or by the game). The basic concept is same as the one used for math functions. In math y=f(x), the function f takes x as a parameter, does something to/with it, and returns a value of y. Same thing here - the function can take one of it's parameters, and can do some processing on it - for example, in HPL script you can use parameters to check which objects collided. When you make a function call, you substitute the x with an actual value (or some other variable which already has a value assigned).

Now, script functions provided by the engine have their own parameter lists, as defined in the documentation, where declarations of these functions are listed. Declarations simply tell you what's the name of the function, what it takes in and what it returns as a result, if anything.
You can also write your own functions, and call them within a script file - you can name them whatever you want, and generally speaking, you make them any kind of parameter list which suits your need.

Here's a quick example. The engine provides a random integer generator RandInt(), and random floating point generator RandFloat(), but not a random bool generator (bool is a type which can have a value of either true or false). No biggie, you can write one yourself and use it in the level.
bool RandBool()     // custom function - completely arbitrary name, no need for parameter list, returns a bool
{
    int result = RandInt(0, 1);   // RandInt() will return either 0 or 1
    return (result == 1);        // returns true if result equals 1, otherwise returns false
}

And then you can use it to do something random ingame:
if(RandBool())       // randomly evaluates to true or false
{
    // do something (only if RandBool() above returned true)...
}

So, for a function to execute, it needs to be called from somewhere - either by you, or by the game itself.
It's important to distinguish between a function declaration/definition (where it's defined how the function "looks" and what it does), and a function call. In the example above, the first code box is the declaration/definition of the RandBool() function, and the "RandBool()" part in the second code box is the function call - when the code execution during gameplay reaches that point, RandBool() gets executed - because you, the scripter, called it.

(12-17-2012, 10:28 AM)nightsxp Wrote: And..how to use if(HasItem)?

void lantern(WHAT SHOULD I PLACE IN HERE?)
{
if(HasItem("lantern") == true)
{

SetEntityActive("block", false);}}
Now, I said some of the functions can be called by the game itself - but only if the game "knows" about them. For example, the OnStart(), OnEnter() and OnLeave() functions are called by the game at certain
points - you will normally not find a call to any of those inside a script file. HPL scripting engine also enables you to tell the game to make a call to a function of your own choice when a certain gameplay event is detected (like a collision). Such a function is know as a callback. But in order for the engine to be able to do that, the callback function must have a certain "format" - the parameter list and the return type of the callback must mach the one that the engine expects (we say: it has to have a certain signature), but you can name the callback function anything you like, and you can make it do anything you like.
To find out what parameter list should be associated with your callback, always consult the documentation on the wiki: the script engine provides special functions you can call, which enable you to hook-up your callback function to a certain event in the game; in the description of these there's always an entry named "Callback syntax", which shows the format (signature) the callback should have, if it was hooked up using that particular function.

Another important point: all callback parameters are input parameters, and are filled in by the game engine when the game decides to make the call (for example, the game detects a entity-player collision, and you specified a callback for that event).
The game uses this to pass you (via the parameters) additional information about the event itself, so that you can check and use those parameters from within your callback function to do something meaningful (if required). The trick is to know what each of the parameters stands for, because it's mostly not described on the wiki, but it's usually easy to figure out from the names of the parameters, or from the description of the function you used to hook-up the callback.

I'll also tell you a "secret" - the callback parameter list has to mach only in data types, and the order of the parameters, but you can name the parameter names anything you want. However, it's a good idea to use meaningful names, which tell you what the parameters are for. For example, for AddEntityCollideCallback() function it says that callback syntax is (bold emphasis by me):
void MyFunc(string &in asParent, string &in asChild, int alState)


What this means is that your callback function must match in the bold parts - the other parts you can change as you see fit - all of these will work as callbacks:
void OnPlayerCollidesMusicArea(string &in asParent, string &in asChild, int alState)
void OnPlayerCollidesMusicArea(string &in entity1, string &in entity2, int collisionState)
void OnPlyrHitsMusicArea(string &in a, string &in b, int state)
void BlahBlah(string &in x, string &in y, int z)

Again, it's a good idea to always use meaningful names for your functions and their parameters. The last one is the worst, since you can't tell what it's for just by looking at it.
Hope that helps you learn how to script. Big Grin
12-17-2012, 01:03 PM
Find
nightsxp Offline
Member

Posts: 53
Threads: 8
Joined: Sep 2011
Reputation: 0
#10
RE: i forgot how to script :c

(12-17-2012, 01:03 PM)TheGreatCthulhu Wrote: I'd like to add a few points to what beecake said, just to clarify a few details, so you can get on track faster and make these kinds of decisions yourself.

(12-14-2012, 08:23 AM)nightsxp Wrote: aand..can you explain what does (string &in asParent, string &in asChild, int alState) mean?
As you've seen if you've read beecake's article, that's what's called a parameter list of a function - basically, these are named variables, which are local to the function (not available for use from outside of the function), and which get their values assigned whenever a call to the function is made (by you, or by the game). The basic concept is same as the one used for math functions. In math y=f(x), the function f takes x as a parameter, does something to/with it, and returns a value of y. Same thing here - the function can take one of it's parameters, and can do some processing on it - for example, in HPL script you can use parameters to check which objects collided. When you make a function call, you substitute the x with an actual value (or some other variable which already has a value assigned).

Now, script functions provided by the engine have their own parameter lists, as defined in the documentation, where declarations of these functions are listed. Declarations simply tell you what's the name of the function, what it takes in and what it returns as a result, if anything.
You can also write your own functions, and call them within a script file - you can name them whatever you want, and generally speaking, you make them any kind of parameter list which suits your need.

Here's a quick example. The engine provides a random integer generator RandInt(), and random floating point generator RandFloat(), but not a random bool generator (bool is a type which can have a value of either true or false). No biggie, you can write one yourself and use it in the level.
bool RandBool()     // custom function - completely arbitrary name, no need for parameter list, returns a bool
{
    int result = RandInt(0, 1);   // RandInt() will return either 0 or 1
    return (result == 1);        // returns true if result equals 1, otherwise returns false
}

And then you can use it to do something random ingame:
if(RandBool())       // randomly evaluates to true or false
{
    // do something (only if RandBool() above returned true)...
}

So, for a function to execute, it needs to be called from somewhere - either by you, or by the game itself.
It's important to distinguish between a function declaration/definition (where it's defined how the function "looks" and what it does), and a function call. In the example above, the first code box is the declaration/definition of the RandBool() function, and the "RandBool()" part in the second code box is the function call - when the code execution during gameplay reaches that point, RandBool() gets executed - because you, the scripter, called it.

(12-17-2012, 10:28 AM)nightsxp Wrote: And..how to use if(HasItem)?

void lantern(WHAT SHOULD I PLACE IN HERE?)
{
if(HasItem("lantern") == true)
{

SetEntityActive("block", false);}}
Now, I said some of the functions can be called by the game itself - but only if the game "knows" about them. For example, the OnStart(), OnEnter() and OnLeave() functions are called by the game at certain
points - you will normally not find a call to any of those inside a script file. HPL scripting engine also enables you to tell the game to make a call to a function of your own choice when a certain gameplay event is detected (like a collision). Such a function is know as a callback. But in order for the engine to be able to do that, the callback function must have a certain "format" - the parameter list and the return type of the callback must mach the one that the engine expects (we say: it has to have a certain signature), but you can name the callback function anything you like, and you can make it do anything you like.
To find out what parameter list should be associated with your callback, always consult the documentation on the wiki: the script engine provides special functions you can call, which enable you to hook-up your callback function to a certain event in the game; in the description of these there's always an entry named "Callback syntax", which shows the format (signature) the callback should have, if it was hooked up using that particular function.

Another important point: all callback parameters are input parameters, and are filled in by the game engine when the game decides to make the call (for example, the game detects a entity-player collision, and you specified a callback for that event).
The game uses this to pass you (via the parameters) additional information about the event itself, so that you can check and use those parameters from within your callback function to do something meaningful (if required). The trick is to know what each of the parameters stands for, because it's mostly not described on the wiki, but it's usually easy to figure out from the names of the parameters, or from the description of the function you used to hook-up the callback.

I'll also tell you a "secret" - the callback parameter list has to mach only in data types, and the order of the parameters, but you can name the parameter names anything you want. However, it's a good idea to use meaningful names, which tell you what the parameters are for. For example, for AddEntityCollideCallback() function it says that callback syntax is (bold emphasis by me):
void MyFunc(string &in asParent, string &in asChild, int alState)


What this means is that your callback function must match in the bold parts - the other parts you can change as you see fit - all of these will work as callbacks:
void OnPlayerCollidesMusicArea(string &in asParent, string &in asChild, int alState)
void OnPlayerCollidesMusicArea(string &in entity1, string &in entity2, int collisionState)
void OnPlyrHitsMusicArea(string &in a, string &in b, int state)
void BlahBlah(string &in x, string &in y, int z)

Again, it's a good idea to always use meaningful names for your functions and their parameters. The last one is the worst, since you can't tell what it's for just by looking at it.
Hope that helps you learn how to script. Big Grin
if i will understand what you have wrote ._.
12-17-2012, 01:11 PM
Find




Users browsing this thread: 1 Guest(s)