time switch?
8 posts
• Page 1 of 1
time switch?
Hey is there a way to make a time based switch. I'll explain. for example if I use right DPAD to turn on a switch, and the switch stay on if I keep using or clicking button for example Left Trigger. And if I dont use the Left Trigger with in 5 seconds the switch turns of automatically. I needed that script plenty of times as it would be useful for lot of things.
-
alencroat - Lieutenant
- Posts: 320
- Joined: Sun Oct 15, 2017 5:58 pm
Re: time switch?
- Code: Select all
int Switch;
uint32 t;
main {
if(event_active(BUTTON_10) & !Switch || (t > 5000)){
t = 0;
Switch = !Switch;
}
if (Switch){
t+=elapsed_time();
if (event_active(BUTTON_8)) { t = 0; }
// code while switch is active
...
combo_run(example);
}
}
combo example {
set_val(20,100);
}
Last edited by Sillyasskid on Fri Jun 15, 2018 4:58 am, edited 1 time in total.
-
Sillyasskid - Captain
- Posts: 574
- Joined: Sat May 14, 2016 3:07 am
Re: time switch?
++t will be a value increasing at some variating speed (1ms and faster).
If you want it to track time passed (milli-seconds) you have to use
t+=elapsed_time();
If you want it to track time passed (milli-seconds) you have to use
t+=elapsed_time();
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: time switch?
interesting let me give it a try thanks boys
-
alencroat - Lieutenant
- Posts: 320
- Joined: Sun Oct 15, 2017 5:58 pm
Re: time switch?
works good, but can you explain how to track it, I added t+=elapsed_time(); to the code but I see nothing. thanks again!
-
alencroat - Lieutenant
- Posts: 320
- Joined: Sun Oct 15, 2017 5:58 pm
Re: time switch?
Scachi wrote:++t will be a value increasing at some variating speed (1ms and faster).
If you want it to track time passed (milli-seconds) you have to use
t+=elapsed_time();
++t will increase every time the main{ } block is called.
Which is 1000 times per seconds.
And there is 1000ms in 1 second.
I'm not saying your wrong though, it was my silly mistake, ideally yes using elapsed_time() is the correct way to go for the most accurate results, I forgot to change that part of the script when I submitted it
Usually when I am testing a script, and I want to implement a timer, I tend to go with ++t, because I'm just testing the timer aspect in general, and not the actual timer value. (I'm lazy) I know that ++t will yield a faster outcome than elapsed_time().
Which is expected because the input controller will generate additional main { } block calls. With every input that gets sent to the titan.
Although, that being said, theoretically as long as the connected input controller is not actually active. ++t and t+=elapsed_time() should produce the exact same results.
-
Sillyasskid - Captain
- Posts: 574
- Joined: Sat May 14, 2016 3:07 am
Re: time switch?
I didn't know I have to use elapsed_time() a few scripts ago. I tried to get a timer working to test something against the time_active function and used ++t. It did take some time before I recognized the cause of my problem.
For me there was a huge difference as it looks like a connected and actively used ds4 controller can result in a much faster rate of main block calls than 1ms.
For me there was a huge difference as it looks like a connected and actively used ds4 controller can result in a much faster rate of main block calls than 1ms.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: time switch?
Scachi wrote:I didn't know I have to use elapsed_time() a few scripts ago. I tried to get a timer working to test something against the time_active function and used ++t. It did take some time before I recognized the cause of my problem.
For me there was a huge difference as it looks like a connected and actively used ds4 controller can result in a much faster rate of main block calls than 1ms.
I'm sure this is due to the gyro values on the PS4 controller.
Every time the titan 2 polls the controller, it will generate an additional main block call if any of the inputs from the controller have actually updated since the last poll interval.
So if the gyros were updating non stop while testing. you would have an additional ~250(max) main block calls. Making the ++t update 1.25 times faster than t+=elapsed_time().
-
Sillyasskid - Captain
- Posts: 574
- Joined: Sat May 14, 2016 3:07 am
8 posts
• Page 1 of 1
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 72 guests