Hello,
I tried to find a guide and implement it myself, but I couldn't, can you help please?
I want to implement this logic (an abstract example so as not to be tied to specific plugins and variables):
I want to write two triggers:
Trigger 1 - the task starts within 10 seconds.
The variable plugin1.value1 changes linearly from 0 to 1 within 10 seconds
The variable plugin1.value2 changes along a curve from 0 to 1 within 10 seconds
The variable plugin2.value3 changes linearly from 0 to 1 5 seconds after the start for 5 seconds
At the seventh second, the plugin3.value4 variable simply changes its value from 5 to 6 (with custom if logic)
Trigger 2 - cancel task (all pending actions must be canceled)
Example Image:
I can write it in Kotlin roughly like this:
It doesn't matter how it can be implemented,using plugins, clean code, I just want to know how to do this as simply and cleanly as possible.
Thank you in advance!
I tried to find a guide and implement it myself, but I couldn't, can you help please?
I want to implement this logic (an abstract example so as not to be tied to specific plugins and variables):
I want to write two triggers:
Trigger 1 - the task starts within 10 seconds.
The variable plugin1.value1 changes linearly from 0 to 1 within 10 seconds
The variable plugin1.value2 changes along a curve from 0 to 1 within 10 seconds
The variable plugin2.value3 changes linearly from 0 to 1 5 seconds after the start for 5 seconds
At the seventh second, the plugin3.value4 variable simply changes its value from 5 to 6 (with custom if logic)
Trigger 2 - cancel task (all pending actions must be canceled)
Example Image:
I can write it in Kotlin roughly like this:
C#:
import kotlinx.coroutines.*
fun main() {
val job = Job()
val scope = CoroutineScope(Dispatchers.Default + job)
scope.launch {
val startTime = System.currentTimeMillis()
while (System.currentTimeMillis() - startTime < 10000) {
val progress = (System.currentTimeMillis() - startTime) / 10000.0
val value1 = progress.coerceIn(0.0, 1.0)
plugin1.value1 = value1
delay(100)
}
startTime = System.currentTimeMillis()
while (System.currentTimeMillis() - startTime < 10000) {
val progress = (System.currentTimeMillis() - startTime) / 10000.0
val value2 = Math.sin(progress * Math.PI).coerceIn(0.0, 1.0)
plugin1.value2 = value2
delay(100)
}
delay(5000)
startTime = System.currentTimeMillis()
while (System.currentTimeMillis() - startTime < 5000) {
val progress = (System.currentTimeMillis() - startTime) / 5000.0
val value3 = progress.coerceIn(0.0, 1.0)
plugin2.value3 = value3
delay(100)
}
delay(7000)
//for example with custom logic !
if (plugin3.value4 < 10)
plugin3.value4=plugin3.value4*2
job.cancelAndJoin()
println("Task canceled")
}
// Trigger 2 (to cancel the task)
val trigger2 = readLine()
if (trigger2 == "cancel") {
job.cancel()
}
}
It doesn't matter how it can be implemented,using plugins, clean code, I just want to know how to do this as simply and cleanly as possible.
Thank you in advance!