Best Way To Reset Labels?

AndrewFromTexas Member Posts: 5 Newcomer

Hey there everyone,

I'm looking into ways to have labels display values within a ui_control callback and then reset to their original label. For example, "Freq".

So far, all I've been able to come up with is using a for loop to create a timer, of sorts, that resets the text after the UI control has been set for a short period of time. The problem is that the amount of time it takes for the loop to complete seems to be inconsistent. If I actually move the knob, the label resets relatively quickly. If I simply click the knob and its value stays the same, the label seems to take longer to reset to its original text. Very strange.

I'm hoping someone might have a better solution than a for loop within the ui control callback.

Here's my compiled test code.

{ Compiled on Fri Jan 28 14:09:06 2022 }
on init
  declare $i
  declare ui_knob $test_knob(0, 1000000, 1) 
  declare ui_label $test_label(1, 1) 
end on

on ui_control($test_knob)
  $i := 0
  while ($i<=1000)
    if ($i=1000)
    end if
  end while
end on

Best Answer


  • soundtrax
    soundtrax Member Posts: 14 Member
    Answer ✓

    Check out the example by EvilDragon in this older thread (post#6):

  • AndrewFromTexas
    AndrewFromTexas Member Posts: 5 Newcomer

    Ah ha! Yea that's exactly what I was looking for. Thank you!

    So, to sum up, EvilDragon says to setup a watchdog timer for each label. From what I gather, the %timer array would have an element for each label that needs the timer.

    Here's the revised test script (in the Sublime KScript Editor) with this working functionality.

    on init 
    	declare const $RESET_TIME := 2000000
    	declare const $RESET_WAIT := (RESET_TIME / 1000) - 500
    	declare timers[1]
    	declare ui_knob test_knob (0, 1000000, 1)
    	declare ui_label test_label (1,1)
    	test_knob -> pos_x := 100
    	test_label -> pos_x := 0
    	test_label -> text := 'TEST'
    end on
    on ui_control (test_knob)
    	test_label -> text := test_knob
    	timers[0] := ENGINE_UPTIME
    	if (ENGINE_UPTIME - timers[0] > RESET_WAIT)
    		test_label -> text := "TEST"
    	end if
    end on
  • corbo-billy
    corbo-billy Member Posts: 81 Helper
    edited January 2022

    And for the knob init callback, we can add :


    Sorry, I don't find the Code Block _

  • RolyB
    RolyB Member Posts: 3 Newcomer


    I've got some reactive/resetting labels laid out as below and haven't had any issues. Of course the number of timers in the array will depend on how many labels you need, and $UIWaitTime can be as long or short as you like - 150000 works well for me. Using this method, your wait time of 1000 is imperceptible on my end, so you may find it needs a couple of extra zeroes!

    on init
       declare %timer[9]
       %timer[0] := 0
       %timer[1] := 0
       %timer[2] := 0
       %timer[3] := 0
       %timer[4] := 0
       %timer[5] := 0
       %timer[6] := 0
       %timer[7] := 0
       %timer[8] := 0
       declare const $UIWaitTime := 1500000
    end on
    on ui_control ($Chor_slider)
        set_text($Chor_label,get_engine_par_disp($ENGINE_PAR_CHORAL_MIX,-1,2,1) & " %")
        if(%timer[6] = 0)
        end if
    end on

    Results have been consistent for me! :D

Back To Top