Frictional Games Forum (read-only)

Full Version: The if ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I often see an "If" in a script.
I tryed to get it but I can't. What the If is for?
When I should use it?
How to script it?

Example:

Function when player touched the door
(mansion_2) :


void TouchDoor(string& asName)
{
if (GetSwingDoorLocked("mansion_2") == true) //checks if the door is locked
{
SetMessage("Messages", "DoorLocked", 0); // if locked --> message appears
}
else // if the door is not locked

SetMessage("Messages", "DoorOpen", 0);
}

The "If" always checks stuff
Ive been thinking what the if is too :/
What if I want to make a monster.
Which followes path nodes but if the player looks at the monster for 3 second. The path nodes will be cleared and the monster followes the player
This is relevant to the first question asked and is mainly directed at Unearthlybrutal concerning "if" loops.

I have this set up:


if (SetEntityActive("m1") == true)
{
SetPlayerLookSpeed(0.5f);
SetPlayerRunSpeed(0.5f);
SetPlayerMoveSpeed(0.5f);}

else

SetPlayerLookSpeed(1f);
SetPlayerRunSpeed(1f);
SetPlayerMoveSpeed(1f);
}

Would this run correctly? The only reason I'm asking instead of testing is because I don't have access to Amnesia right now.
(03-06-2012, 06:27 PM)Nevicar Wrote: [ -> ]This is relevant to the first question asked and is mainly directed at Unearthlybrutal concerning "if" loops.

I have this set up:


if (SetEntityActive("m1") == true)
{
SetPlayerLookSpeed(0.5f);
SetPlayerRunSpeed(0.5f);
SetPlayerMoveSpeed(0.5f);}

else

SetPlayerLookSpeed(1f);
SetPlayerRunSpeed(1f);
SetPlayerMoveSpeed(1f);
}

Would this run correctly? The only reason I'm asking instead of testing is because I don't have access to Amnesia right now.
I'm not sure about that will the "SetEntityActive" work with the "If".

But if it will, this should work:
Spoiler below!

void function(syntax)
{
if (SetEntityActive("m1") == true)
{
SetPlayerLookSpeed(0.5f);
SetPlayerRunSpeed(0.5f);
SetPlayerMoveSpeed(0.5f);}
}

else

SetPlayerLookSpeed(1f);
SetPlayerRunSpeed(1f);
SetPlayerMoveSpeed(1f);
}


Thanks a lot! Will be sure to try when I get home.
When I want to Clear the Path nodes if the Player looks at the monster for 3 Seconds. Should the script look like this?

if (PlayerLookAt("m1") == true)

{
AddTimer("", 3, "MonsterClear");
}
void MonsterClear(string &in asTimer)
{
if (PlayerLookAt("m1") == true)


{
ClearEnemyPatrolNodes("m1");
}



(03-07-2012, 01:46 PM)Shives Wrote: [ -> ]When I want to Clear the Path nodes if the Player looks at the monster for 3 Seconds. Should the script look like this?

if (PlayerLookAt("m1") == true)

{
AddTimer("", 3, "MonsterClear");
}
void MonsterClear(string &in asTimer)
{
if (PlayerLookAt("m1") == true)


{
ClearEnemyPatrolNodes("m1");
}
No, go to the look function.


What I've to do with the look function?