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
tonitoni1998 Offline
Member

Posts: 163
Threads: 54
Joined: Oct 2012
Reputation: 1
#1
Only call a function when 2 condictions are fulfilled

i want to show a messge when the player is standing inside of an are and is looking at an entity.

When you are looking for someone, to do the scripting for your Custom Story, ask me!
02-12-2013, 07:44 PM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#2
RE: Only call a function when 2 condictions are fulfilled

Add a collide callback for the area, and a look callback for the entity.

When the player enters the area, set a variable to true. When he leaves, set the same variable to false.
When the player looks at the entity, set another variable to true. When he stops looking, set the same variable to false.

In both functions, call a third function like: void DoStuffIfPlayerIsInAreaAndLookingAtEntity()
where you check the 2 variables.

[Image: 16455.png]
(This post was last modified: 02-12-2013, 07:47 PM by MulleDK19.)
02-12-2013, 07:47 PM
Find
tonitoni1998 Offline
Member

Posts: 163
Threads: 54
Joined: Oct 2012
Reputation: 1
#3
RE: Only call a function when 2 condictions are fulfilled

im sorry, im a newbie to coding. i dont know wich variable you mean. i only know how to set a collide callback to enter, leave and both. and im not sure how to change that look at and look away. can you please give me a kickstart?

When you are looking for someone, to do the scripting for your Custom Story, ask me!
(This post was last modified: 02-12-2013, 08:34 PM by tonitoni1998.)
02-12-2013, 07:57 PM
Find
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




Users browsing this thread: 1 Guest(s)