Frictional Games Forum (read-only)

Full Version: How to have more scripts then one at a time.[Solved]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
}
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.
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.
Let's say I want to add another key to the game, how do I put it without the game crashing?
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");
}
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?
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");
}