Facebook Twitter YouTube Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Shelf | Store

Privacy Policy


Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved How to have more scripts then one at a time.[Solved]
Author Message
clock123 Offline
Member

Posts: 76
Joined: Jul 2011
Reputation: 0
Post: #1
How to have more scripts then one at a time.[Solved]
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
}
(This post was last modified: 07-29-2011 09:26 AM by clock123.)
07-28-2011 10:27 AM
Find all posts by this user Quote this message in a reply
MrCookieh Offline
Member

Posts: 157
Joined: Jul 2011
Reputation: 0
Post: #2
RE: How to have more scripts then one at a time.
{
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.

The Well: Descent - Take a look at it!
07-28-2011 11:09 AM
Find all posts by this user Quote this message in a reply
palistov Offline
Posting Freak

Posts: 1,175
Joined: Mar 2011
Reputation: 56
Post: #3
RE: How to have more scripts then one at a time.
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.

07-28-2011 11:51 AM
Find all posts by this user Quote this message in a reply
clock123 Offline
Member

Posts: 76
Joined: Jul 2011
Reputation: 0
Post: #4
RE: How to have more scripts then one at a time.
Let's say I want to add another key to the game, how do I put it without the game crashing?
07-28-2011 06:03 PM
Find all posts by this user Quote this message in a reply
MrCookieh Offline
Member

Posts: 157
Joined: Jul 2011
Reputation: 0
Post: #5
RE: How to have more scripts then one at a time.
you mean another key, which opens a door?
do the same like you did it with your first key:
AddUseItemCallback("", "Key2", "Door2", "KeyOnDoor2", true);
and then your function:
void KeyOnDoor2(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("Door2", false, true);
PlaySoundAtEntity("", "unlock_door", "door2", 0, false);
RemoveItem("Key2");
}

The Well: Descent - Take a look at it!
07-28-2011 06:09 PM
Find all posts by this user Quote this message in a reply
clock123 Offline
Member

Posts: 76
Joined: Jul 2011
Reputation: 0
Post: #6
RE: How to have more scripts then one at a time.
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?
07-28-2011 06:45 PM
Find all posts by this user Quote this message in a reply
MrCookieh Offline
Member

Posts: 157
Joined: Jul 2011
Reputation: 0
Post: #7
RE: How to have more scripts then one at a time.
Your script with the second key:
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");
}

The Well: Descent - Take a look at it!
07-28-2011 07:07 PM
Find all posts by this user Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)