Jump to content
Sign in to follow this  
drunken officer

how to script a "check" if value getting higher or lower

Recommended Posts

I've a simple problem

I want to add 2 differnt sounds to my animations.

closecell and opencell

while {true} do
{....
_blah = _this select 0;
_cc = "closecell";
_ulc = "unlock"
_oc = "opencell";
_anim0 = _blah animationPhase 'Open_cell_1';

if (_anim0 > 0 and _anim0 < 0.1 ) then {_blah say [_ulc,30,1];_blah say [_oc,30,1] };
if (_anim0 > 0.9 and _anim0 < 1) then {_blah say [_cc,30,1];};
};

So how is to command to check if the anim0 geeting higher or getting lower?

i tryed if

 if (_anim0 > 0 and _anim0 < 0.1 and _anim0 ++) then ....

= no working

then i tryed

if (_anim0 > 0 and _anim0 < 0.1 and [_ blah animate [""Open_zelle_1"", 1]) then...
or
(_anim0 > 0 and _anim0 < 0.1 and [_ blah animate [""Open_zelle_1"", 1] = true]) then ...

not working.

Share this post


Link to post
Share on other sites

Something along these lines maybe...

// initial/last animation state
_anim0 = _blah animationPhase 'Open_cell_1';

while {(alive _blah)} do  // exit loop if _blah is dead/destroyed
{
  // current animations state
  _anim1 = _blah animationPhase 'Open_cell_1';

  switch (true) do
  {
     case (_anim0 < _anim1): { /* ... */ };
     case (_anim0 > _anim1): { /* ... */ };
  };

  // update last animation state
  _anim0 = _anim1;

  sleep 0.05;
};

^^ maybe put the sleep command into the case-code-block (as a cooldown), so if the animation has changed, there is a (longer) sleep, so that the sound doesn't get triggered x-times in a second, while opening/closing that door.

Edited by ruebe

Share this post


Link to post
Share on other sites

SOLVED!

I used a counter to help.


if (_anim0 > 0 and _anim0 < 1) then {_anim0counter = _anim0counter + 1} else {_anim0counter = 0};
// setting the counter. Anim = 0 or 1 -> counter = 0. Between the counter getting higher +1
player globalChat format["%1",_anim0counter]; // check if it works
if (_anim0counter < 2 and _anim0 < 0.1 and _anim0 > 0) then {_blah say [_ulc,30,1];_blah say [_oc,30,1] };
// blocking sound if counter > 2
if (_anim0 > 0.9 and _anim0 < 1 and _anim0counter < 2) then {_blah say [_cc,30,1];}; // blocking sound if counter > 2

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  

×