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
HELP!!!
JPPSJ Offline
Junior Member

Posts: 20
Threads: 2
Joined: Apr 2012
Reputation: 0
#11
RE: HELP!!!

(04-17-2012, 12:46 AM)Putmalk Wrote: Okay, so, first, we have a mapping problem. In our map, we are going to have a door called "mansion_1", an area called "AreaSlamDoor", and that's pretty much it. Our player is always called "Player" when referred to by the script.

So, when we collide with AreaSlamDoor, mansion_1 will be shut closed!

How do we do this?

First, we add a callback in our OnStart function so that the game knows when the player will collide with the area.

void OnStart()
{
    //Hey! This is a comment. Any text following "//" will not affect your script at all!
    //Player is our parent, it collides with our child, AreaSlamDoor.
    //When it does, SlamDoor function is called, with a specific callback that you will find in the Engine Scripts webpage
    //That "true" means we are deleting the callback when the player enters the area, so it won't trigger twice by accident
    //That 0 pretty much means it will trigger when the player enters or leaves the area, it doesn't matter.
    AddEntityCollideCallback("Player", "AreaSlamDoor", "SlamDoor", true, 0);

}

void OnEnter()
{

}

void OnLeave()
{

}

//see that weird stuff in the parantheses? That's a function argument...you'll find this following every function that needs in the Engine scripts I linked above!
void SlamDoor(string &in asParent, string &in asChild, int alStates)
{
    //this function got called when player touches Area
    //The door "mansion_1" will be closed because the first boolean statement (true or false) is set to true
    //Effects will be shown because the second boolean argument is set to true as well
    SetSwingDoorLocked("mansion_1", true, true);
    //We deal 10 sanity damage to the player, and we will show effects on his screen because true is set for use effects!
    GiveSanityDamage(10, true);
    //the "doorslam" could be anything, this is just so that can easily identify the sound
    //we play the 15_slam_door sound effect, located in this sounds folder of Amnesia directory, because it sounds like a slam door!
    //Don't worry about the true or false in this function
    //0.4 seconds (notice the "f", it's there because this is a float (there's a decimal in the number) to fade out
    PlaySoundAtEntity("doorslam", "15_slam_door.snt", "mansion_1", 0.4f, false);
}

That should work for you. Don't copy and paste that code, write it out and study my comments, it is the only way you will learn syntax and how to code!

There are many advanced methods on how to script, but you are a beginner and this is how you need to learn.
Ok, thank so much. can you please post another comment showing everything without the notes inbetween?


04-17-2012, 12:52 AM
Find
Putmalk Offline
Senior Member

Posts: 290
Threads: 13
Joined: Apr 2012
Reputation: 15
#12
RE: HELP!!!

void OnStart()
{
//player collide with slamdoor
  AddEntityCollideCallback("Player", "AreaSlamDoor", "SlamDoor", true, 0);
}

void OnEnter()
{

}

void OnLeave()
{

}

void SlamDoor(string &in asParent, string &in asChild, int alState)
{
    //slam door, with sound, effect, and sanity damage
    SetSwingDoorLocked("mansion_1", true, true);
    GiveSanityDamage(10, true);
    PlaySoundAtEntity("doorslam", "15_slam_door.snt", "mansion_1", 0.4f, false);
}

(This post was last modified: 04-17-2012, 12:54 AM by Putmalk.)
04-17-2012, 12:53 AM
Find
JPPSJ Offline
Junior Member

Posts: 20
Threads: 2
Joined: Apr 2012
Reputation: 0
#13
RE: HELP!!!

(04-17-2012, 12:53 AM)Putmalk Wrote:
void OnStart()
{
//player collide with slamdoor
  AddEntityCollideCallback("Player", "AreaSlamDoor", "SlamDoor", true, 0);
}

void OnEnter()
{

}

void OnLeave()
{

}

void SlamDoor(string &in asParent, string &in asChild, int alState)
{
    //slam door, with sound, effect, and sanity damage
    SetSwingDoorLocked("mansion_1", true, true);
    GiveSanityDamage(10, true);
    PlaySoundAtEntity("doorslam", "15_slam_door.snt", "mansion_1", 0.4f, false);
}
Do i add //slam door, with sound, effect, and sanity damage? or [/code]?


04-17-2012, 12:57 AM
Find
Putmalk Offline
Senior Member

Posts: 290
Threads: 13
Joined: Apr 2012
Reputation: 15
#14
RE: HELP!!!

In your script, you can add anything you want if it is preceded by "//", because that tells the computer that the line is a comment and to ignore everything past it. It doesn't check it for syntax. Comments are there so that you can tell yourself what is going on, or else you will forget, and I promise you, you will forget a lot. So always comment what the code is doing so you know what's going on!

[/code] is for these forums, not for scripting.

04-17-2012, 12:59 AM
Find
Xanthos Offline
Senior Member

Posts: 318
Threads: 9
Joined: Mar 2012
Reputation: 8
#15
RE: HELP!!!

EDIT: I got ninja'd

(This post was last modified: 04-17-2012, 01:01 AM by Xanthos.)
04-17-2012, 01:00 AM
Find
JPPSJ Offline
Junior Member

Posts: 20
Threads: 2
Joined: Apr 2012
Reputation: 0
#16
RE: HELP!!!

(04-17-2012, 12:59 AM)Putmalk Wrote: In your script, you can add anything you want if it is preceded by "//", because that tells the computer that the line is a comment and to ignore everything past it. It doesn't check it for syntax. Comments are there so that you can tell yourself what is going on, or else you will forget, and I promise you, you will forget a lot. So always comment what the code is doing so you know what's going on!

[/code] is for these forums, not for scripting.
Ok i will try this. i will post what i scripted if it doesnt work maby u coukd tell me what i did wrong. thanks soo mch!


04-17-2012, 01:01 AM
Find
Putmalk Offline
Senior Member

Posts: 290
Threads: 13
Joined: Apr 2012
Reputation: 15
#17
RE: HELP!!!

Yup, glad I can help. Just please don't copy/paste. You won't learn a thing.

04-17-2012, 01:02 AM
Find
JPPSJ Offline
Junior Member

Posts: 20
Threads: 2
Joined: Apr 2012
Reputation: 0
#18
RE: HELP!!!

(04-17-2012, 01:02 AM)Putmalk Wrote: Yup, glad I can help. Just please don't copy/paste. You won't learn a thing.


Wait, does this go under void on leave?
void SlamDoor(string &in asParent, string &in asChild, int alState)
{
//slam door, with sound, effect, and sanity damage
SetSwingDoorLocked("mansion_1", true, true);
GiveSanityDamage(10, true);
PlaySoundAtEntity("doorslam", "15_slam_door.snt", "mansion_1", 0.4f, false);

04-17-2012, 01:08 AM
Find
Putmalk Offline
Senior Member

Posts: 290
Threads: 13
Joined: Apr 2012
Reputation: 15
#19
RE: HELP!!!

Functions aren't constrained to "below or above" any other function (at least in our game scripts!). It can technically go anywhere. For example, in the main game scripts, onstart and other functions are at the bottom of the script; sometimes, I have them on the top. Location doesn't matter.

What does matter is that you're not putting the functions inside of other functions, like this:

OnStart()
{

   OnLeave()
   {

   }

}

That's bad.

04-17-2012, 01:11 AM
Find
JPPSJ Offline
Junior Member

Posts: 20
Threads: 2
Joined: Apr 2012
Reputation: 0
#20
RE: HELP!!!

(04-17-2012, 01:11 AM)Putmalk Wrote: Functions aren't constrained to "below or above" any other function (at least in our game scripts!). It can technically go anywhere. For example, in the main game scripts, onstart and other functions are at the bottom of the script; sometimes, I have them on the top. Location doesn't matter.

What does matter is that you're not putting the functions inside of other functions, like this:

OnStart()
{

   OnLeave()
   {

   }

}

That's bad.
Ok, so i put everthing you put in
void OnStart()
{
"your example"
}


04-17-2012, 01:13 AM
Find




Users browsing this thread: 1 Guest(s)