Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Only call a function when 2 condictions are fulfilled
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#4
RE: Only call a function when 2 condictions are fulfilled

The most common condition checking mechanism is the 'if' statement.

An example would be

if(yourCondition1 && yourCondition2) {
// Do some cool code here!
} else {
// This code runs only if the conjuctive expression
// (yourCondition1 && yourCondition2) evaluates to false!
}

The && symbol is a boolean operator 'and'. It basically means for the condition to be met, both yourCondition1 and yourCondition2 must be met.

You can describe your conditions many ways and you can do the condition checking in multiple places. You can do it before calling the function, or you can do it inside the function, and simply don't run any code unless the condition is met.

Anyways you need to describe your conditions as boolean values, true or false. To expand on MulleDK's example:

Goal:
If the player is in the area 'MyArea' and is looking at area 'DoorArea', give him a lantern.

(We'll assume that the global variable 'IsInMyArea' is a boolean variable that changes when the player enters or exits 'MyArea', and the global variable 'IsLookingAtDoorArea' represents whether the player is looking at the door or not.)

void LanternGift() {
if(IsInMyArea && IsLookingAtDoor) {
GivePlayerItemFromFile("LanternGift", "lantern.ent");
} else {
// No gift for you!
}
}

This is a primitive example and requires you manually change the global variables to keep them up to date, so that whenever you evaluate them they are accurate. You would change the IsInMyArea variable in a callback function to area callbacks, which you said you know how to do. The same goes for the IsLookingAtDoor variable, except with a SetEntityPlayerLookAt callback. Check out the wiki page for more info on that function. Good luck.

02-12-2013, 08:53 PM
Find


Messages In This Thread
RE: Only call a function when 2 condictions are fulfilled - by palistov - 02-12-2013, 08:53 PM



Users browsing this thread: 1 Guest(s)