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
Conditional function activation?
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#1
Conditional function activation?

I'm having a lot of trouble keeping functions from activating until a certain condition is fulfilled. My first example is trying to activate a grunt after the player goes down a hallway, picks up a hammer, and comes back down the same hallway. I've tried to use an "if" statement, but every time I try, the function activates the first time you go down the hallway, and fails to work properly since you're not holding the right item. Then when you come back out, it doesn't reactivate a second time.

Here are the two scripts I've tried:
Spoiler below!
void CollideActivateLiveGrunt(string &in asParent, string &in asChild, int alState)
{
if(HasItem("stone_hammer_1"))
{
SetEntityActive("servant_grunt_1", true);
}
}

void OnStart()
{
AddEntityCollideCallback("Player", "PlayerFake", "CollideActivateLiveGrunt", true, 1);
}

Spoiler below!
void CollideActivateLiveGrunt(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("servant_grunt_1", true);
}

void OnStart()
{
if(HasItem("stone_hammer_1"))
{
AddEntityCollideCallback("Player", "PlayerFake", "CollideActivateLiveGrunt", true, 1);
}
}

Another problem is having a lever display two different messages depending on whether you've used an item on it yet or not. But, as soon as you touch it, it wastes both functions before you use the item on it and won't display the second message after you use the item.

(This post was last modified: 03-14-2012, 05:06 AM by Damascus.)
03-14-2012, 03:58 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: Conditional function activation?

First off, you'll want to change true to false in your AddEntityCollideCallback line. The true signifies that the callback will be removed once triggered, meaning your function will run only once. Changing it to false lets the callback run each time the collision happens, so that once the player returns to the hallway with the hammer, the function will run again.

Secondly, this semantics bug is likely stemming from a map cache issue. I see nothing wrong syntactically nor semantically in your code. Try adding some debug messages to see (visually) the value of HasItem("stone_hammer_1"). Do something like AddDebugMessage("does player have hammer: "+HasItem("stone_hammer_1"), false);

Thirdly, if you want to do this a different way, you can leave true as is, and simply add the collision callback after the player picks up the hammer. This is a simple way to bypass the conditional and at the same time take advantage of the auto-remove feature of collision callbacks, so you don't have to remove it manually.

To do this, create a function called HammerPick or something similar. Next, select your hammer item in the level editor. Go to the second tab, and in the PlayerInteractCallback field write HammerPick. The function takes one parameter, a string. Then just stick the AddEntityCollideCallback line in that function, and you can totally disregard your if statement in CollideActivateLiveGrunt function.

PHP Code: (Select All)
void HammerPick(string &in hammerRef)
{
//just an example to show you the parameter


Off to MW3~!

(This post was last modified: 03-14-2012, 04:39 AM by palistov.)
03-14-2012, 04:36 AM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#3
RE: Conditional function activation?

Ah, man I feel stupid for not getting this. Both things work now! Thank you!

03-14-2012, 05:06 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#4
RE: Conditional function activation?

No problem. Don't feel stupid, it's all a learning process Smile

03-14-2012, 06:12 AM
Find




Users browsing this thread: 2 Guest(s)