Frictional Games Forum (read-only)
Multiple use of a void OnStart, need help D: - 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: Multiple use of a void OnStart, need help D: (/thread-16010.html)

Pages: 1 2 3


Multiple use of a void OnStart, need help D: - ApeCake - 06-09-2012

Hi guys, I am new to scripting and I am currently trying out almost all the script on the wiki. However, most of the ones I want to use require void OnStart(). This didn't seem like a problem to me, but I somehow can't get multiple scripts to work with void OnStart().

Example;


void OnStart()

{
AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true);
SetEntityCallbackFunc("key_1", "OnPickup");
}
void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("locked_door1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "locked_door1", 0, false);
RemoveItem("key_1");
}
void OnPickup(string &in asEntity, string &in type)
{
SetEntityActive("monster_grunt", true);
ShowEnemyPlayerPosition("monster_grunt");
}
//new thing here
{
AddEntityCollideCallback("Player", "Message_1", "Message1", true, 1);
}
void Message1(string &in asChild, string &in asParent, int alState)
{
SetMessage("Messages", "popuptext1", 5);
}

void OnEnter()
{
}

void OnLeave()
{
}


When starting up my map, an error shows up saying ''main (18, 1) : ERR : Unexpected Token '{'.
But when I remove the { and } on 18, another error comes by showing ''main (19, 25) : ERR : Expected indentifier. However, I have no idea how to fix this. If this is the way to do it, how do I add this 'indentifier? This seems to be so simple! Am I just missing something easy?

I am sorry if this has been asked before, I couldn't find anything like this. Also forgive me for any grammar/spelling errors. Not my native language, you see.


RE: Multiple use of a void OnStart, need help D: - palistov - 06-09-2012

Under your line //new thing here is a code block that is out of place. You can't stick blocks of code arbitrarily around, they need an identifier, which essentially says what it is and/or under what circumstances it is run.


RE: Multiple use of a void OnStart, need help D: - ApeCake - 06-09-2012

(06-09-2012, 10:11 PM)palistov Wrote: Under your line //new thing here is a code block that is out of place. You can't stick blocks of code arbitrarily around, they need an identifier, which essentially says what it is and/or under what circumstances it is run.
Yeah, but that part needs to be with void OnStart(). I guess void OnStart() is an indentifier? But if I put void OnStart() there it says I can't put void OnStart() twice...


RE: Multiple use of a void OnStart, need help D: - Ermu - 06-09-2012

(06-09-2012, 10:43 PM)ApeCake Wrote:
(06-09-2012, 10:11 PM)palistov Wrote: Under your line //new thing here is a code block that is out of place. You can't stick blocks of code arbitrarily around, they need an identifier, which essentially says what it is and/or under what circumstances it is run.
Yeah, but that part needs to be with void OnStart(). I guess void OnStart() is an indentifier? But if I put void OnStart() there it says I can't put void OnStart() twice...
You can do this:
put this inside your void OnStart
NewThing();

and then place this anywhere, outside OnStart, OnLeave, and OnEnter

NewThing()
{

}


RE: Multiple use of a void OnStart, need help D: - JenniferOrange - 06-09-2012

void OnStart()

{
AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true);
SetEntityCallbackFunc("key_1", "OnPickup");
AddEntityCollideCallback("Player", "Message_1", "Message1", true, 1);

}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("locked_door1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "locked_door1", 0, false);
RemoveItem("key_1");
}

void OnPickup(string &in asEntity, string &in type)
{
SetEntityActive("monster_grunt", true);
ShowEnemyPlayerPosition("monster_grunt");
}

void Message1(string &in asChild, string &in asParent, int alState)
{
SetMessage("Messages", "popuptext1", 5);
}

void OnEnter()
{
}

void OnLeave()
{
}

That should do it.


RE: Multiple use of a void OnStart, need help D: - ApeCake - 06-10-2012

(06-09-2012, 11:04 PM)JenniferOrange Wrote: void OnStart()

{
AddUseItemCallback("", "key_1", "locked_door1", "UsedKeyOnDoor", true);
SetEntityCallbackFunc("key_1", "OnPickup");
AddEntityCollideCallback("Player", "Message_1", "Message1", true, 1);

}

void UsedKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("locked_door1", false, true);
PlaySoundAtEntity("", "unlock_door.snt", "locked_door1", 0, false);
RemoveItem("key_1");
}

void OnPickup(string &in asEntity, string &in type)
{
SetEntityActive("monster_grunt", true);
ShowEnemyPlayerPosition("monster_grunt");
}

void Message1(string &in asChild, string &in asParent, int alState)
{
SetMessage("Messages", "popuptext1", 5);
}

void OnEnter()
{
}

void OnLeave()
{
}

That should do it.
Thanks Jennifer! It worked. Love your tutorials!


RE: Multiple use of a void OnStart, need help D: - KeysOfMyMind - 03-16-2013

So hi guys.
i'm new to scripting and I want this script to work and it should, but it doesn't for some reason.



void OnStart()
{
AddUseItemCallback("", "crowbar_1", "mansiondoor1", "UsedCrowbarOnDoor", true);
AddEntityCollideCallback("crowbar_joint_1", "ScriptArea_Joint", "CollideAreaBreakDoor", true, 1);
}


void UsedCrowbarOnDoor(string &in asItem, string &in asEntity)
{
AddTimer("", 0.2, "TimerSwitchShovel");
RemoveItem("crowbar_1");
}


void TimerSwitchShovel(string &in asTimer)
{
PlaySoundAtEntity("","puzzle_place_jar.snt", "", 0, false);
SetEntityActive("crowbar_joint_1", true);
}


void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
AddPlayerSanity(25);
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
SetSwingDoorLocked("mansiondoor1", false, true);
AddPropImpulse("mansiondoor1", 0, 0, -50, "World");
SetSwingDoorDisableAutoClose("mansiondoor1", true);
SetSwingDoorClosed("mansiondoor1", false, false);
SetMoveObjectState("mansiondoor1", 1);
PlaySoundAtEntity("","break_wood_metal", "ScriptArea_Dust", 0, false);
CreateParticleSystemAtEntity("", "ps_hit_wood", "ScriptArea_Dust", false);
SetEntityActive("crowbar_joint_1", false);
SetLocalVarInt("Door", 1);
}

//Scare Here
{
AddEntityCollideCallback("Player", "push", "Push", true, 1);
AddEntityCollideCallback("Player", "door_slam", "Slam", true, 1);
}


void Push(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
AddPlayerBodyForce(30000, 0, 0, false);
}


void Slam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("mansiondoor1", true, true);
SetSwingDoorLocked("mansiondoor1", true, true);
PlaySoundAtEntity("", "00_laugh.snt", "door_scare", 0, false);
}

My scare part crashes the game.
Some help please.

Also I'd like to make it so that I have another area the player hits up against the wall where he collapses and gasps from hitting the wall.
Also the value for the AddPlayerBodyForce propels the player forward, I'd like him to be push backwards into the wall area.


RE: Multiple use of a void OnStart, need help D: - PutraenusAlivius - 03-16-2013

(03-16-2013, 03:27 PM)KeysOfMyMind Wrote: So hi guys.
i'm new to scripting and I want this script to work and it should, but it doesn't for some reason.



void OnStart()
{
AddUseItemCallback("", "crowbar_1", "mansiondoor1", "UsedCrowbarOnDoor", true);
AddEntityCollideCallback("crowbar_joint_1", "ScriptArea_Joint", "CollideAreaBreakDoor", true, 1);
}


void UsedCrowbarOnDoor(string &in asItem, string &in asEntity)
{
AddTimer("", 0.2, "TimerSwitchShovel");
RemoveItem("crowbar_1");
}


void TimerSwitchShovel(string &in asTimer)
{
PlaySoundAtEntity("","puzzle_place_jar.snt", "", 0, false);
SetEntityActive("crowbar_joint_1", true);
}


void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
AddPlayerSanity(25);
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
SetSwingDoorLocked("mansiondoor1", false, true);
AddPropImpulse("mansiondoor1", 0, 0, -50, "World");
SetSwingDoorDisableAutoClose("mansiondoor1", true);
SetSwingDoorClosed("mansiondoor1", false, false);
SetMoveObjectState("mansiondoor1", 1);
PlaySoundAtEntity("","break_wood_metal", "ScriptArea_Dust", 0, false);
CreateParticleSystemAtEntity("", "ps_hit_wood", "ScriptArea_Dust", false);
SetEntityActive("crowbar_joint_1", false);
SetLocalVarInt("Door", 1);
}

//Scare Here
{
AddEntityCollideCallback("Player", "push", "Push", true, 1);
AddEntityCollideCallback("Player", "door_slam", "Slam", true, 1);
}


void Push(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "react_pant.snt", "push", 0, false);
AddPlayerBodyForce(30000, 0, 0, false);
}


void Slam(string &in asParent, string &in asChild, int alState)
{
SetSwingDoorClosed("mansiondoor1", true, true);
SetSwingDoorLocked("mansiondoor1", true, true);
PlaySoundAtEntity("", "00_laugh.snt", "door_scare", 0, false);
}

My scare part crashes the game.
Some help please.

Also I'd like to make it so that I have another area the player hits up against the wall where he collapses and gasps from hitting the wall.
Also the value for the AddPlayerBodyForce propels the player forward, I'd like him to be push backwards into the wall area.

Put the AddEntityCollideCallback parts to your void OnStart(), so that it will look like this.
PHP Code:
void OnStart()
{
AddUseItemCallback("""crowbar_1""mansiondoor1""UsedCrowbarOnDoor"true);
AddEntityCollideCallback("crowbar_joint_1""ScriptArea_Joint""CollideAreaBreakDoor"true1);
AddEntityCollideCallback("Player""push""Push"true1); AddEntityCollideCallback("Player""door_slam""Slam"true1);

To make the player to be pushed backwards, change to force from 30000 to -30000.


RE: Multiple use of a void OnStart, need help D: - No Author - 03-16-2013

You could have just create a new thread instead bumping a year old thread.


RE: Multiple use of a void OnStart, need help D: - PutraenusAlivius - 03-16-2013

(03-16-2013, 03:49 PM)No Author Wrote: You could have just create a new thread instead bumping a year old thread.

He's a new guy, just get off his back.