Jump to content
Sign in to follow this  
Winters

On Deactivation

Recommended Posts

Hi,

I am trying to use a trigger that will add an event handler to the player once he is a trigger radius. I am also trying to use the on deactivation part of said trigger to remove the EH so if you leave the triggers radius your no longer able to use the EH.

The problem is the on deactivation part wont remove my EH, the remove EH only works when i put it in the script the EH calls when activated.

Any ideas?

Thanks in advance biggrin_o.gif

Share this post


Link to post
Share on other sites

On deactivation, set a global variable: deact = true and test for it and exit if true in your event handler script.

Share this post


Link to post
Share on other sites

If for some reason you cannot remove the event handler in deactivation, as an alternative:

1. Define a global variable, such as DeactivateEH. Set it to "true" in the trigger's deactivation field.

2. In the script that gets called by the event handler, test for condition DeactivateEH. If true, exit the script.

Share this post


Link to post
Share on other sites

Ok, i never worked with testing before.

would i have to do something like:

if deactivateEH= true then remove eventhandler ["fired", 0]

im not sure if thats the right syntax i am using.

Share this post


Link to post
Share on other sites
Ok, i never worked with testing before.

I'll go easy on yas, what you being such a mission making novice. tounge_o.gif

Quote[/b] ]

would i have to do something like:

if deactivateEH= true then remove eventhandler ["fired", 0]

im not sure if thats the right syntax i am using.

I think it's:

? DeactivateEH : object removeEventHandler [type, index]

Here's the ComRef for removeEventHandler:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">object removeEventHandler handler

Operand types:

   object: Object

   handler: Array

Compatibility:

   Version 1.85 required.

Type of returned value:

   Nothing

Description:

   Removes event handler added by addEventHandler. Format of handler is [type,index]. Index is returned by addEventHandler. When any handler is removed, all handler indices higher that the deleted one should be decremented.

Example:

   player removeEventHandler ["killed",0]

Share this post


Link to post
Share on other sites

I meant testing for different conditions not testing in general  tounge_o.gif

my way returned an "error unknown operator" message

i tried it like this:

if (deactivateeh= true) then {student remove eventhandler ["fired", 0]}

it looked like that was the way to go in the comref but what the heck do i know  rock.gif

Share this post


Link to post
Share on other sites

You do know that to use the deactivation of a trigger you need to have it on activated repeatedly, right?

Variables are not needed in this instance; just putting this in the triggers deactivation should work fine.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">student removeevenhandler ["fired", 0]

RED

Share this post


Link to post
Share on other sites
I meant testing for different conditions not testing in general  tounge_o.gif

my way returned an "error unknown operator" message

i tried it like this:

if (deactivateeh= true) then {student remove eventhandler ["fired", 0]}

it looked like that was the way to go in the comref but what the heck do i know  rock.gif

Try:

if (deactivateeh)

That would mean it's true. Just like checking for a condition in a trigger's condition field.

Again, as an alternative, if you cannot get the removeEventHandler to work, try this at the top of your EH script:

if (deactivateeh) then exit

smile_o.gif

Share this post


Link to post
Share on other sites
Variables are not needed in this instance; just putting this in the triggers deactivation should work fine.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">student removeevenhandler ["fired", 0]

I'm only posting an alternative, as Winters is claiming the removeEventHandler command is not working.

Share this post


Link to post
Share on other sites

The trigger i used was set on repeatedly and it had an on activation of not only you being present but also a condition to be set to true which would be set in your script.

So, we have 2 overlapping triggers. One which waits for a condition to be set to true and for your presence in the area and that will show the objstatus as done. and the other which is waiting for your presence and then gives the player his eventhandler it is in this eventhandler that you activate the script to set the condition to true to accomplish the objective.

What i am trying to accomplish here is that the player will not be able to run into the trigger area, then leave it and activate the eventhandler outside the trigger area and then just run back through the trigger area which will then see "detect" as true and see you presence inside the are thus setting obj1 to "done".

I want to force the player to be inside the trigger area when he activates the EH, thats why i was trying to get the EH removed upon deactivation of the trigger i.e. you leave the triggers area.

Share this post


Link to post
Share on other sites

Why don't you just give the trigger area an name and in your EH script start with:

? not (player in list triggerAreaName): exit

rock.gif

Share this post


Link to post
Share on other sites

So you have one trigger that activates once something is done, with something like this in the activationfield:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Obj1Done = true

Then the second trigger that adds the eventhandler has condition field like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">This && Obj1Done

Activationfield:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player addeventhandler ["Fired", {hint "Bang"}]

DeAcativation:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player removeeventhandler ["Fired",0]

Is that what you mean? Or am I way off base?

RED

Share this post


Link to post
Share on other sites

Ok, here goes;

Trigger 1:

Activated by: West being present

Condition: this

On Activation: student addeventhandler ["fired", {_this exec "script1.sqs"}]

Script1 will then set the condition detect= true

Trigger 2:

Activated by: West being present

Condition: this && detect

On Activation: "1" objstatus "ACTIVE"; "1" objstatus "DONE"

I tried to add the removeeventhandler to trigger 1 in the on deactivation field but it didnt work.

Share this post


Link to post
Share on other sites

Strange, can you email me the mission? Or just the part you can't get to work? Graham_uk@btopenworld.com

RED

P.S. I just added you to my ICQ list if you would rather not send me the mission.

Share this post


Link to post
Share on other sites

Red, i will add you to my ICQ when i get home, i just sent ya a PM in the meanwhile.

Share this post


Link to post
Share on other sites

Here is the test I made :

A rectangular trigger, set on Repeatedly.

Activation : hint "in";player addEventHandler ["fired",{MyVar=true}]

On Deactivation : hint "out";player removeEventHandler ["fired",0]

Another trigger, with MyVar as a condition, and Hint "MyVar" in the Activation field.

This works perfectly well : if you're inside the first trigger and you shoot, MyVar will be hinted. If you're out, it won't.

I think the test reproduces the effect you want, so the problem as I see it comes from somewhere else : does your student have other "fired" EHs ? In which case you'd have to find the correct index of the EH you want to remove.

Share this post


Link to post
Share on other sites

I did a similar test to that Igor and it worked correctly too, there must be something you have overlooked Winters. Are you sure the trigger is deactivating? Try putting a hint into it to make sure it is.

RED

Share this post


Link to post
Share on other sites

I ran a test in which i put in the on deactivation field:

deactivate= true

i then set up a game logic with the condition deactivate and had it show some text "hey dude deactivation is working"

this worked fine. but, when i went back an tried to remove the EH the same trouble started up again.

I did solve the problem by using AvonLadys suggestion:

? not (student in list trig1): exit

at the top of the script my EH calls, i can then remove the EH in the script after student does his thing.

It's strange how i can get text a condition to be set throught the on deactivation field but that i can't get it to work to remove an EH.

Thanks for the help Avon, Red & Igor.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×