Solved wait "%{_variable}% minutes" parsed as timespan doesn't work

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

RedDiamond

Member
Nov 30, 2020
21
0
1
23
So I tried to make a function that will run something and set a variable into a number that will be used for "wait", after that it'll wait for that amount of variable time to run the function again. Look I know the explanation might be very confusing and make no sense but this is the code:
Code:
function testRate():
  if {testChange} = true:
    set {incRateTest.percent} to random number between 5 and 10 # increase percentage
    set {incRateTest.wait} to random integer between 15 and 20 # number for "wait"
    set {_incValtest} to (rounded down ({valtest} * ({incRateTest.percent} / 100)))
    add {_incValtest} to {valtest} #the value after being increased
    wait 5 ticks
    broadcast "%nl%&e&lCONVERTION RATE INCREASE%nl%&7"
    broadcast " &6| &ePercentage: &f%{incRateTest.percent}%%%"
    broadcast " &6| &eNext Change: &f%{incRateTest.wait}% &fseconds%nl%&7"
    set {incRateTest.waitTime} to "%{incRateTest.wait}% seconds" parsed as timespan # time until next increasement
    set {incRateTest.timeWait} to now # this is for another line of code to tell the time difference until the next increasement
    set {incRateTest.waitForNext} to "%{incRateTest.wait}% seconds" parsed as timespan # this is tp set the "wait" time parsed as timespan
    wait {incRateTest.waitForNext}
    testRate()
  else if {testChange} = false:
    stop

Now the problem is that it run the function again even before the set time. For example if the wait is 10 seconds, it'll run the function again at 7 seconds. Idk how to fix this, is this a problem with my code or a bug, pls help me I'm so desperate. If you need more info I can provide them if I have it. Thank you :emoji_slight_smile:
 
So I tried to make a function that will run something and set a variable into a number that will be used for "wait", after that it'll wait for that amount of variable time to run the function again. Look I know the explanation might be very confusing and make no sense but this is the code:
Code:
function testRate():
  if {testChange} = true:
    set {incRateTest.percent} to random number between 5 and 10 # increase percentage
    set {incRateTest.wait} to random integer between 15 and 20 # number for "wait"
    set {_incValtest} to (rounded down ({valtest} * ({incRateTest.percent} / 100)))
    add {_incValtest} to {valtest} #the value after being increased
    wait 5 ticks
    broadcast "%nl%&e&lCONVERTION RATE INCREASE%nl%&7"
    broadcast " &6| &ePercentage: &f%{incRateTest.percent}%%%"
    broadcast " &6| &eNext Change: &f%{incRateTest.wait}% &fseconds%nl%&7"
    set {incRateTest.waitTime} to "%{incRateTest.wait}% seconds" parsed as timespan # time until next increasement
    set {incRateTest.timeWait} to now # this is for another line of code to tell the time difference until the next increasement
    set {incRateTest.waitForNext} to "%{incRateTest.wait}% seconds" parsed as timespan # this is tp set the "wait" time parsed as timespan
    wait {incRateTest.waitForNext}
    testRate()
  else if {testChange} = false:
    stop

Now the problem is that it run the function again even before the set time. For example if the wait is 10 seconds, it'll run the function again at 7 seconds. Idk how to fix this, is this a problem with my code or a bug, pls help me I'm so desperate. If you need more info I can provide them if I have it. Thank you :emoji_slight_smile:
If I am correct, your issue is having the wait inside the function. A function can be called/run multiple times, but the delay within the function itself doesn't change how often it's run but instead is for if you wanted the function to do one thing, wait, then do another. To fix your issue, move the wait time variable outside of the function and rearrange it so that it'd be something like this:

Code checks if a certain wait time is set, if not, it runs the function. If the wait time is set, the function is run after the specified wait time var and the last line it would run (In the function itself) would be to clear the wait time variable (This would be so that the data from the previous wait does not keep adding exponentially the next time(s) your function is run). Hopefully this is hopeful!
 
If I am correct, your issue is having the wait inside the function. A function can be called/run multiple times, but the delay within the function itself doesn't change how often it's run but instead is for if you wanted the function to do one thing, wait, then do another. To fix your issue, move the wait time variable outside of the function and rearrange it so that it'd be something like this:

Code checks if a certain wait time is set, if not, it runs the function. If the wait time is set, the function is run after the specified wait time var and the last line it would run (In the function itself) would be to clear the wait time variable (This would be so that the data from the previous wait does not keep adding exponentially the next time(s) your function is run). Hopefully this is hopeful!
Okay! Thank you for the explanation and the help :emoji_slight_smile: