Frictional Games Forum (read-only)
The if and if else statements - 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: The if and if else statements (/thread-21108.html)



The if and if else statements - T122002 - 04-09-2013

Hello everyone! I have a question to ask.

Most script functions I have a general idea on how to use, but I do not understand how the "if" and "if else" statements work, or how or when to use them. I think after I learn those two statements, than I'll start working with loops and try to mess with puzzles a bit more.

Well, for example, say I want the player to pick up a key, then when they leave the room the key was in, a monster spawns. Or maybe when you do something, like solve a puzzle (I also don't know how to do puzzle scripts), then something will happen.

Can anyone explain to me how to do this, like dumb it down so I can understand and maybe throw in a few examples for me to study? That would be much appreciated!


RE: The if and if else statements - OriginalUsername - 04-09-2013

You could see it as asking a if question.

IF the door is closed, do this. ELSE do this.
Example:
Code:
if((ifyourdoorislocked, ifplayerhasanitem) == true or false)
{
Do some things
}
Else
{
Do other things
}
I'll give you a link to all these commands once I'm back on my pc

Hope it helps!

Edit: I see your computer already gave the link, good luck Wink


RE: The if and if else statements - Your Computer - 04-09-2013

(04-09-2013, 06:06 PM)T122002 Wrote: Well, for example, say I want the player to pick up a key, then when they leave the room the key was in, a monster spawns.

Technically, you don't need if and else statements for that. Just have an interact callback for the key that adds a collision callback for leaving an area that then activates a monster.

(04-09-2013, 06:06 PM)T122002 Wrote: Or maybe when you do something, like solve a puzzle (I also don't know how to do puzzle scripts), then something will happen.

Depending on the puzzle's complexity you also may not need if and else statements.

You can find some information on if-else statements here: http://wiki.frictionalgames.com/hpl2/amnesia/script_language_reference_and_guide/control_flow_-_conditional_statements


RE: The if and if else statements - T122002 - 04-09-2013

(04-09-2013, 08:32 PM)Your Computer Wrote:
(04-09-2013, 06:06 PM)T122002 Wrote: Well, for example, say I want the player to pick up a key, then when they leave the room the key was in, a monster spawns.

Technically, you don't need if and else statements for that. Just have an interact callback for the key that adds a collision callback for leaving an area that then activates a monster.

(04-09-2013, 06:06 PM)T122002 Wrote: Or maybe when you do something, like solve a puzzle (I also don't know how to do puzzle scripts), then something will happen.

Depending on the puzzle's complexity you also may not need if and else statements.

You can find some information on if-else statements here: http://wiki.frictionalgames.com/hpl2/amnesia/script_language_reference_and_guide/control_flow_-_conditional_statements

Hmm..well okay. At least I won't need the if and if else stuff right now then, since you answered exactly what I wanted. But, what are the script functions to pull off the interact callback and the collision callback? I can't find them at the Engine Scripts page, unless they're named differently there.
And thanks for the link for the if else thing, its very helpful! Big Grin


RE: The if and if else statements - OriginalUsername - 04-10-2013

Not sure which page you were looking at, but they're located here: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions


RE: The if and if else statements - T122002 - 04-10-2013

(04-10-2013, 07:05 AM)Smoke Wrote: Not sure which page you were looking at, but they're located here: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions

I saw the site, but I couldn't find the functions.
Your Computer said this:
"Technically, you don't need if and else statements for that. Just have an interact callback for the key that adds a collision callback for leaving an area that then activates a monster."

Is there a specific function on how to do this? I mean, how would I set that up?


RE: The if and if else statements - PutraenusAlivius - 04-10-2013

(04-10-2013, 03:37 PM)T122002 Wrote:
(04-10-2013, 07:05 AM)Smoke Wrote: Not sure which page you were looking at, but they're located here: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions

I saw the site, but I couldn't find the functions.
Your Computer said this:
"Technically, you don't need if and else statements for that. Just have an interact callback for the key that adds a collision callback for leaving an area that then activates a monster."

Is there a specific function on how to do this? I mean, how would I set that up?
void OnStart()
{
SetEntityCallbackFunc("KeyName", "AreaActive");
}

void AreaActive(string &in asEntity, string &in type)
{
SetEntityActive("NameOfArea", true);
AddEntityCollideCallback("Player", "NameOfArea", "MonsterTrigger", true, 1);
}

void MonsterTrigger(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("MonsterName", true);
}

---
Used using SECF, SEA, and AECC. You can functions and conditional functions in the link provided.


RE: The if and if else statements - T122002 - 04-10-2013

(04-10-2013, 03:44 PM)JustAnotherPlayer Wrote:
(04-10-2013, 03:37 PM)T122002 Wrote:
(04-10-2013, 07:05 AM)Smoke Wrote: Not sure which page you were looking at, but they're located here: http://wiki.frictionalgames.com/hpl2/amnesia/script_functions

I saw the site, but I couldn't find the functions.
Your Computer said this:
"Technically, you don't need if and else statements for that. Just have an interact callback for the key that adds a collision callback for leaving an area that then activates a monster."

Is there a specific function on how to do this? I mean, how would I set that up?
void OnStart()
{
SetEntityCallbackFunc("KeyName", "AreaActive");
}

void AreaActive(string &in asEntity, string &in type)
{
SetEntityActive("NameOfArea", true);
AddEntityCollideCallback("Player", "NameOfArea", "MonsterTrigger", true, 1);
}

void MonsterTrigger(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("MonsterName", true);
}

---
Used using SECF, SEA, and AECC. You can functions and conditional functions in the link provided.

Ooh! Thank you so much for the functions! This was exactly what I was looking for!