1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

ui_label and make_persistent

Discussion in 'Scripting Workshop' started by Jesse01, Nov 7, 2021.

  1. Jesse01

    Jesse01 New Member

    Messages:
    14
    Hi all!

    I have a ui_label png image showing the percentage values of a knob, when i save my project in the DAW and open it again i see that the knob is still in the same value but the ui_label is back to 0, i know that because i'm using make_persistent for the knob so it's saved and i also know that make_persistent can't be used with ui_label is there a way around that?
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You need to set_text() of the label in persistence_changed callback.
     
  3. Jesse01

    Jesse01 New Member

    Messages:
    14
    I have set_text() here is my code:

    Code:
     declare ui_label $Percent(0, 20)
     set_text ($Percent,"")
     hide_part($Percent,   $HIDE_PART_TITLE)
    move_control_px($Percent, 100, 100)
    set_control_par_str(get_ui_id($Percent),  $CONTROL_PAR_PICTURE, "Percent_img")
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Yeah, so then you need to move that set_text() to "on persistence_changed" callback and print the knob value you want. The label should be declared as (1, 1), not (0, 20), and there's also no need to $HIDE_PART_TITLE, that one doesn't apply to ui_labels...
     
  5. Jesse01

    Jesse01 New Member

    Messages:
    14
    Can you give me an example in the code please i've never worked with on persistence_changed before
     
  6. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Just put set_text() in that callback and that's it. Example is in KSP reference.
     
  7. Jesse01

    Jesse01 New Member

    Messages:
    14
    Thanks for your response!
    Can you tell me which page exactly on the KSP Manual that you are referring to?
     
  8. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    Difficult to find an similar example to yours but by searching in this KSP manual with the keywords: set text label, we can see the usage.

    For information: Sets the control text, similar to set_text () _
    It's written on page 256 of KSPmanual but no similar situation to yours. To find it, carrying out a search with the search engine of this forum can also help you.
     
  9. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    set_text_label() applies to ui_knob only, not ui_label, though.
     
  10. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    Ah, sorry for my wrong explanation .:rolleyes:
     
  11. Jesse01

    Jesse01 New Member

    Messages:
    14
    Yeah i've been working with the KSP manual examples all night yesterday without any luck...
     
  12. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    Perhaps with your entire script, that would be easier ...?
     
    • Like Like x 1
  13. Jesse01

    Jesse01 New Member

    Messages:
    14
    Here:

    Code:
    on init
     make_perfview
      set_ui_height_px(200)
    
    declare ui_slider $fx01(0, 20)
      hide_part($fx01,  $HIDE_PART_BG .or. $HIDE_PART_MOD_LIGHT .or. $HIDE_PART_TITLE .or. $HIDE_PART_VALUE)
      set_control_par_str(get_ui_id($fx01),  $CONTROL_PAR_PICTURE,"fx_img")
      move_control_px($fx01, 50, 100)
      set_control_par(get_ui_id($fx01), $CONTROL_PAR_MOUSE_BEHAVIOUR, -1000)
      $fx01 := 500000
     make_persistent($fx01)
    
     declare ui_label $Percent(0, 20)
     set_text ($Percent,"")
    move_control_px($Percent,  100, 100)
    set_control_par_str(get_ui_id($Percent),  $CONTROL_PAR_PICTURE, "Percent_img")
    
    end on
    on ui_control ($fx01)
    set_control_par(get_ui_id($Percent),$CONTROL_PAR_PICTURE_STATE ,$fx01)
    end on
     
  14. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    That's pretty inefficient if you're gonna use a graphic for all the % values... You could just use a custom picture font in Kontakt 6 instead.

    At any rate, copy your set_control_par() line into "on persistence_changed" callback.
     
  15. Jesse01

    Jesse01 New Member

    Messages:
    14


    As i mentioned before i really don't know how to add the persistence_changed the only examples i saw on KSP manual that includes persistence_changed have function.. I'm still a rookie lol:rolleyes:
     
  16. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    So replace that function from that example to that single line you have in ui_control callback... It's a callback like any other, it is created like any other...
     
  17. Jesse01

    Jesse01 New Member

    Messages:
    14
    I did but no luck
     
  18. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    What do you mean "no luck"? You get any error message, or?
     
  19. Jesse01

    Jesse01 New Member

    Messages:
    14
    yeah i just keep getting errors
     
  20. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    What is the exact code you're having there? Paste it all.