Frictional Games Forum (read-only)

Full Version: Question about basic scripting.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Need help with something, how do i combine code?

I want the following two scipts/codes in the same .hps file:



void OnStart()
{
GiveItemFromFile("lantern", "lantern.ent");

for(int i=0;i< 10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
}


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_brute", true);
ShowEnemyPlayerPosition("monster_brute");
}



I tried multiple things, watched multiple tutorials and browsed multiple topics, but still couldn't find what i was looking for!

Help IS appreciated. Thanks!
Well you see. There can't be 2 functions called "OnStart".

So what you have to do with the void OnStart() is to combine them.
Like this:

PHP Code:
void OnStart()

GiveItemFromFile("lantern""lantern.ent");
for(
int i=0;i10;i++) GiveItemFromFile("tinderbox_"+i"tinderbox.ent"); 

AddUseItemCallback("""key_1""locked_door1""UsedKeyOnDoor"true);
SetEntityCallbackFunc("key_1""OnPickup");


Makes sense, hmm?

Always remember: There cannot be 2 functions with the same name.

I've only skimmed over the other functions, as the OnStart seemed the most obvious.
Try it out, and see if it works.

If it doesn't, please return here, and explain what happens.

If you get an error, show it to us.
If you get something else, show it.
(03-11-2015, 09:02 PM)FlawlessHappiness Wrote: [ -> ]Well you see. There can't be 2 functions called "OnStart".

So what you have to do with the void OnStart() is to combine them.
Like this:

PHP Code:
void OnStart()

GiveItemFromFile("lantern""lantern.ent");
for(
int i=0;i10;i++) GiveItemFromFile("tinderbox_"+i"tinderbox.ent"); 

AddUseItemCallback("""key_1""locked_door1""UsedKeyOnDoor"true);
SetEntityCallbackFunc("key_1""OnPickup");


Makes sense, hmm?

Always remember: There cannot be 2 functions with the same name.

I've only skimmed over the other functions, as the OnStart seemed the most obvious.
Try it out, and see if it works.

If it doesn't, please return here, and explain what happens.

If you get an error, show it to us.
If you get something else, show it.




Hey,

The game doesn't crash, but it also doesn't fully work. What's supposed to happen is:

1: When player starts the map, he will start with a Lantern and 10 Tinderboxes (works).

2: When player picks up a key, a Monster spawns (doesn't work).



EDIT: The "Monster spawn" script works when i start the document with that code. But then "1" won't do anything anymore (still no crash, gets completely ignored).
Well they don't work, because you have split the callbacks in 2 different void OnStart()

The script is supposed to look like this:
PHP Code:
void OnStart()

GiveItemFromFile("lantern""lantern.ent");

for(
int i=0;i10;i++) GiveItemFromFile("tinderbox_"+i"tinderbox.ent");

AddUseItemCallback("""key_1""locked_door1""UsedKeyOnDoor"true);
SetEntityCallbackFunc("key_1""OnPickup");
}


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

void OnPickup(string &in asEntitystring &in type)
{
SetEntityActive("monster_brute"true);
ShowEnemyPlayerPosition("monster_brute");


Notice that there is only 1 "void OnStart()"
They both work now, thank you very much!

I see what i did wrong. Now just going to play around with some more code and see how it goes.


Thanks!
I'm glad it works!

Feel free to ask more questions.