blazeda59 Posted August 1, 2011 Share Posted August 1, 2011 Can someone please help me with my timer for the life of me I cant get it to work. The disabling of the player and the animations all work fine but only as soon as the player sits in the chair not after a 5 sec delay. Here's my code I've tried several different ways but none work. float fTimer; short doOnce BEGIN GameMode if (player.IsCurrentFurnitureRef seatREF) set fTimer to 5 if ( fTimer == 0 ) if ( doOnce == 0 ) doorREF.PlayGroup Backward 0 DisablePlayerControls 1 1 1 0 0 1 1 set doOnce to 1 else set fTimer to fTimer + GetSecondsPassed endif endif endif END Link to comment Share on other sites More sharing options...
sagittarius22 Posted August 1, 2011 Share Posted August 1, 2011 Can someone please help me with my timer for the life of me I cant get it to work. The disabling of the player and the animations all work fine but only as soon as the player sits in the chair not after a 5 sec delay. Here's my code I've tried several different ways but none work. float fTimer; short doOnce BEGIN GameMode if (player.IsCurrentFurnitureRef seatREF) set fTimer to 5 if ( fTimer == 0 ) if ( doOnce == 0 ) doorREF.PlayGroup Backward 0 DisablePlayerControls 1 1 1 0 0 1 1 set doOnce to 1 else set fTimer to fTimer + GetSecondsPassed endif endif endif END Could you please try to change this line:set fTimer to fTimer + GetSecondsPassedby this one:set fTimer to fTimer - GetSecondsPassed Link to comment Share on other sites More sharing options...
blazeda59 Posted August 1, 2011 Author Share Posted August 1, 2011 hey thanks for the quick reply. I just tried what you suggested but still no luck :wallbash: Link to comment Share on other sites More sharing options...
Tefnacht Posted August 1, 2011 Share Posted August 1, 2011 (edited) Hi. I am not sure if I understand exactly what you want. I assume it is this: Once the player sits down on seatREF for more than fife seconds you want some of his controls disabled and the door to animate? If he stands up again before the fife seconds are up nothing should happen. Is that it? Then this snippet should do what you want: Short doonce ;set to 1 once the timed event happened Float fTimer ;timer to count up Begin GameMode If doonce == 0 ;if the timed event was not yet triggered If Player.IsCurrentFurnitureRef seatREF ;if the player is sitting on the seat Set fTimer To fTimer + GetSecondsPassed ;increment the timer If fTimer >= 5 ;if the timer ran for 5 seconds or more Set doonce To 1 ;prevent the event form happening again doorREF.PlayGroup Backward 0 ;start the door animation DisablePlayerControls 1 1 1 0 0 1 1 ;disable some player controls EndIf Else ;otherwise the player is not sitting on the seat Set fTimer To 0 ;reset timer to zero EndIf EndIf End If it isn't, you should maybe explain what you want to happen in a few more words. One word of general advice: If you work with floating point numbers, you should always avoid the == (equal) operator like the plaque and use >= (greater or equal) and <= (less or equal) instead. “fTimer == 0” would only be true if fTimer is really exactly 0 which is usually very unlikely with a floating point number modified by GetSecondsPassed (which is also a small float).It could be 0.0021 on first pass, which is not == 0 and then -0.0033 on second pass which is also not == 0.== (equal) and != (not equal) should usually only be used with integer numbers (short, long or int), never float. I hope this helps you. Good luck. Edited August 1, 2011 by Tefnacht Link to comment Share on other sites More sharing options...
blazeda59 Posted August 1, 2011 Author Share Posted August 1, 2011 thanks Tefnacht its working now :biggrin: now how would I add a second call to the timer 5 secs after the first to display a message? i tried just adding If fTimer >= 10 in a new if statement and adding a second timer but had no luck Link to comment Share on other sites More sharing options...
blazeda59 Posted August 2, 2011 Author Share Posted August 2, 2011 (edited) dose anyone know how I would do it? EDIT: nevermind I got it but one other thing I'd like to know is how to set the state of an object with a script not attached to it? Edited August 2, 2011 by blazeda59 Link to comment Share on other sites More sharing options...
Glenstorm Posted August 2, 2011 Share Posted August 2, 2011 dose anyone know how I would do it? EDIT: nevermind I got it but one other thing I'd like to know is how to set the state of an object with a script not attached to it? Name the reference of the object in the world. You can do this by opening the object in Render window and typing something in the ID area. Also make it persistent, I'm not sure if you need to make it persistent for all cases but do it anyway. Then in any script, simply call <refID>.enable or other commands as normal. Link to comment Share on other sites More sharing options...
blazeda59 Posted August 2, 2011 Author Share Posted August 2, 2011 that doesn't seem to work. this is my setup I have an object thats animating when triggered but unless I change its state from 0 to 1 using "set State to" it keeps triggering the same animation over and over. but I need the player to be able to trigger it again once a second animation plays which is from a second script. My problem is I need to be able to change the state back to 0 from the second script but "wallREF.set State to 0" wont work. Link to comment Share on other sites More sharing options...
Glenstorm Posted August 2, 2011 Share Posted August 2, 2011 that doesn't seem to work. this is my setup I have an object thats animating when triggered but unless I change its state from 0 to 1 using "set State to" it keeps triggering the same animation over and over. but I need the player to be able to trigger it again once a second animation plays which is from a second script. My problem is I need to be able to change the state back to 0 from the second script but "wallREF.set State to 0" wont work. .setState to 0. No spaces. Link to comment Share on other sites More sharing options...
blazeda59 Posted August 2, 2011 Author Share Posted August 2, 2011 still no good now the script wont save Link to comment Share on other sites More sharing options...
Recommended Posts