Frictional Games Forum (read-only)
How to have more scripts then one at a time.[Solved] - 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: How to have more scripts then one at a time.[Solved] (/thread-9444.html)



How to have more scripts then one at a time.[Solved] - clock123 - 07-28-2011

Hey, when ever I add more then one script into my game files to my custom map it crashes, how should I fix that?, here's what I'm trying to add.

Spoiler below!
void OnStart()

{
AddUseItemCallback("", "Key1", "Door1", "KeyOnDoor", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("Door1", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("Key1");
}

{
ConnectEntities("door_connection", //Name of connection
"Lever1", //Parent entity (Affects)
"Shelf", //Child entity (Affected)
false, //Invert the state sent
1, //States used (0=both), checked before invertion.
"CreateDust"); //callback
}



RE: How to have more scripts then one at a time. - MrCookieh - 07-28-2011

Code:
{
ConnectEntities("door_connection", //Name of connection
"Lever1", //Parent entity (Affects)
"Shelf", //Child entity (Affected)
false, //Invert the state sent
1, //States used (0=both), checked before invertion.
"CreateDust"); //callback
}

this is not a proper function. It needs a head (void example(...){}) to work (like your
void KeyOnDoor(...){}).

So you have to decide: Should the code trigger automatically at the beginning, then put it
in the OnStart(){}. Otherwise, add your Callback in your OnStart() and the function for the
callback before the {.

If you don't understand it, then you can tell me what should happen, that the function gets triggered, so I can give you an example code.


RE: How to have more scripts then one at a time. - palistov - 07-28-2011

If you're referring to multiple script files, then no. Just one script file is required. If you're referring to co-routines (multiple functions being executed at the same time) then yes it is possible and very easy to do with AngelScript.

Looking at your code example, you need to make sure you use appropriate syntax and scripting practices. You have a call stack without a name/type! If that braced call stack is supposed to be part of the 'KeyOnDoor' function, just remove the two middle braces. All lines in the function will be executed at the same time. You can use double fore-slashes to indicate a comment line with which you can organize and/or label your call stack.

You can combine functions when appropriate but there is always support for co-routines when needed.


RE: How to have more scripts then one at a time. - clock123 - 07-28-2011

Let's say I want to add another key to the game, how do I put it without the game crashing?


RE: How to have more scripts then one at a time. - MrCookieh - 07-28-2011

you mean another key, which opens a door?
do the same like you did it with your first key:
Code:
AddUseItemCallback("", "Key2", "Door2", "KeyOnDoor2", true);
and then your function:
Code:
void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("Door2", false, true);
PlaySoundAtEntity("", "unlock_door", "door2", 0, false);
RemoveItem("Key2");
}



RE: How to have more scripts then one at a time. - clock123 - 07-28-2011

So I put the new key-script in the same line with the same french brackets or making a new line with new french brackets?


RE: How to have more scripts then one at a time. - MrCookieh - 07-28-2011

Your script with the second key:
Code:
void OnStart()

{
AddUseItemCallback("", "Key1", "Door1", "KeyOnDoor", true);
AddUseItemCallback("", "Key2", "Door2", "KeyOnDoor2", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("Door1", false, true);
PlaySoundAtEntity("", "unlock_door", "door1", 0, false);
RemoveItem("Key1");
}

void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("Door2", false, true);
PlaySoundAtEntity("", "unlock_door", "door2", 0, false);
RemoveItem("Key2");
}