Frictional Games Forum (read-only)
[SPOILER] Some Script-Problems - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SPOILER] Some Script-Problems (/thread-20257.html)



Some Script-Problems - BlueRsX - 02-09-2013

Hey Guys!
Im working on a custom story in Amnesia.
So I've watched tutorials and guides, on the wiki too.
So... For my map I need some scripts and functions. And I dont find it so easy to write them, so I've copied the "Door-Smash"-Code from the Wiki. Thanks for it!

So heres my question: I have a code. How can I write 2 codes one after another? I tried just to seperate them with a } one after another,
but I got every time an error like "ERROR" "Unexpected end of file" or something. I will post the code here for you:
Quote:////////////////////////////
// Run first time starting map
void OnStart()
{
AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
}

void func_slam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("door2", true, true);

PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);

PlaySoundAtEntity("", "react_scare", "Player", 0, false); PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);

GiveSanityDamage(5.0f, true);
}
(HERES THE 2ND CODE v v v v v v v)
{
SetEntityPlayerInteractCallback("door1", "func_slam", true);
}


void func_slam(string &in asParent, string &in asChild, int alState)
{
SetPropHealth("door1", 0.0f);


PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);


PlaySoundAtEntity("", "react_scare", "Player", 0, false);


PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);


GiveSanityDamage(5.0f, true);
}
////////////////////////////
// Run when entering map
void OnEnter()
{

}
////////////////////////////
// Run when leaving map
void OnLeave()
{

}


So heres the error, if i dont put the } between[/quote]:
http://prntscr.com/s3vwb

Can someone tell me what is wrong or how can i save to scripts without an error?

Thank you!

-Blue Smile


RE: Some Script-Problems - NaxEla - 02-09-2013

You can also put
Code:
SetEntityPlayerInteractCallback("door1", "func_slam", true);
in OnStart.

Your OnStart function will look like this:
PHP Code:
void OnStart()
{
    
AddEntityCollideCallback("Player""script_slam""func_slam"true1);
    
SetEntityPlayerInteractCallback("door1""func_slam"true);




RE: Some Script-Problems - The chaser - 02-09-2013

The good script should be like this:

Code:
////////////////////////////

// Run first time starting map

void OnStart()

{

AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
SetEntityPlayerInteractCallback("door1", "func_slam_1", true);

}



void func_slam(string &in asParent, string &in asChild, int alState)

{

SetSwingDoorClosed("door2", true, true);



PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);



PlaySoundAtEntity("", "react_scare", "Player", 0, false);  PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);



GiveSanityDamage(5.0f, true);

}

    





void func_slam_1(string &in asParent, string &in asChild, int alState)

{

SetPropHealth("door1", 0.0f);





PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);





PlaySoundAtEntity("", "react_scare", "Player", 0, false);





PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);





GiveSanityDamage(5.0f, true);

}

////////////////////////////

// Run when entering map

void OnEnter()

{



}

////////////////////////////

// Run when leaving map

void OnLeave()

{



}



RE: Some Script-Problems - BlueRsX - 02-09-2013

@NaxEla
Thank you guys very much! But what was the mistake in my code? What is the connection-Problem beteween both?


RE: Some Script-Problems - palistov - 02-09-2013

You can't do what you're trying to do. The braces { } enclose blocks of code. That second set of code you're trying to include must be put into a new function.

So if you want to run func_slam and then the "second" piece of code separately, put the second piece into "func_slam2" or some other function of your choice, and run it separately from the other code.


RE: Some Script-Problems - BlueRsX - 02-09-2013

Okay Thx! And a last question: So I can just separate 2 codes, when I leave spaces between them? Is it so easy?


RE: Some Script-Problems - palistov - 02-09-2013

Yeah everything in a block of code will run unless you direct it otherwise with other statements, which I won't get into.

Just remember that whatever is between the braces will be run when the function is called.


RE: Some Script-Problems - BlueRsX - 02-09-2013

Thank you, but I think im the stupidest person on the world Big Grin

So I need a bit help with this code...
I wanna make a closed door, wich I have to open with a key.
Code:
void OnStart()

{
AddUseItemCallback("", "Schluessel", "Schluesseltuer", "FUNCTION", true);
}

void FUNCTION(string &in asItem, string &in asEntity)

{
    SetSwingDoorLocked(asEntity, false, true);
    PlaySoundAtEntity("", "unlock_door", asEntity, 0, false);
    RemoveItem(asItem);
    SetSwingDoorClosed("door2", true, true);
    }

So everything works... Thank god!

Then I wanna make this "breakdown" of this door for a scary moment.
Ive got the script and everythings fine.
So I tried to insert that "breakdown" code in the .hps file.

Im not sure how to insert it, because I get every time an error!
I tried it like this:
Code:
void OnStart()

{
AddUseItemCallback("", "Schluessel", "Schluesseltuer", "FUNCTION", true);
AddEntityCollideCallback("Player", "script_slam", "func_slam", true, 1);
}

void FUNCTION(string &in asItem, string &in asEntity)

{
    SetSwingDoorLocked(asEntity, false, true);
    PlaySoundAtEntity("", "unlock_door", asEntity, 0, false);
    RemoveItem(asItem);
    SetSwingDoorClosed("door2", true, true);
    }
    
    {
void func_slam(string &in asParent, string &in asChild, int alState)
    PlaySoundAtEntity("", "react_breath_slow.snt", "Player", 0, false);
    PlaySoundAtEntity("", "react_scare", "Player", 0, false);  PlaySoundAtEntity("", "close_door.snt", "Player", 0, false);
    GiveSanityDamage(5.0f, true);

}

But I always got an error. The programm says:
Could not load script blablabla: (20,5):ERR: Unexpected token {

So I just deleted this "{" But another error:
(22,5) expected , or ;
(23,22) expected identifier
(23,81) expected identifier
(24,21) expected identifier
(26,1) unexpected token }


Then I just tried to copy the 2nd code just behind the 1st with and without braces, but it allways errors...

I just cant understand why it cant work!

Help again? I know Im annoying Big Grin


RE: Some Script-Problems - BlueRsX - 02-10-2013

Ok Ive got everything! Thank you!