Saving Slider Positions

Andrew Finch
Andrew Finch Member Posts: 17 Newcomer

Hi Guys,

I am trying to rework this script:

on init 
    
    declare %save[3] {number of mic signals}
    declare $sync_id 
    declare ui_slider $Slider1 (0,100000) 
    declare ui_slider $Slider2 (0,100000) 
    declare ui_slider $Slider3 (0,100000) 
    
    declare ui_menu $Menu 
    declare $tmp
    declare const $GFX := -1		 
    declare const $GROUP := 0
    
    add_menu_item($Menu,"Save",0) 
    add_menu_item($Menu,"Load",1) 
    
end on 


on async_complete 
    if ($NI_ASYNC_ID = $sync_id) 
        $sync_id := -1 
    end if 
end on 


on ui_control ($Menu) 
    select ($Menu) 
        case 0 
            save_array (%save,0)  
        case 1 
            $sync_id := load_array (%save,0) 
            while ($sync_id # -1) 
                wait (1) 
            end while     
            $Slider1 := %save[0] 
            $Slider2 := %save[1] 
            $Slider3 := %save[2] 
    end select 
    
end on 


on ui_control($Slider1) 
	set_engine_par($ENGINE_PAR_FORMANT,$Slider1,$GROUP,0,$GFX)
	$tmp := get_engine_par($ENGINE_PAR_FORMANT,$GROUP,0,$GFX)
    %save[0] := $Slider1 
end on


on ui_control($Slider2) 
	set_engine_par($ENGINE_PAR_FORMANT,$Slider2,$GROUP,0,$GFX)
	$tmp := get_engine_par($ENGINE_PAR_FORMANT,$GROUP,0,$GFX)
    %save[1] := $Slider2 
end on


on ui_control($Slider3) 
	set_engine_par($ENGINE_PAR_FORMANT,$Slider2,$GROUP,0,$GFX)
	$tmp := get_engine_par($ENGINE_PAR_FORMANT,$GROUP,0,$GFX)
    %save[2] := $Slider3
end on

I don't want to access load and save through a menu but as two separate buttons, how would I go about this? I have looked in the KSP Manual and it only shows examples of using tables so I am not sure how to do it. Thanks in advance!

Answers

  • EvilDragon
    EvilDragon Moderator Posts: 1,022 mod

    You would just do it with two buttons, so you split each case of that $Menu's select-case into separate UI callbacks for load and save. Pretty simple.

  • Andrew Finch
    Andrew Finch Member Posts: 17 Newcomer

    That's great, have just worked that out! Is there a way to print the name of the preset onto the gui? Also I was thinking could you load say 6 presets for different combinations of buttons and then have a button that cycles between those six loaded presets?

  • EvilDragon
    EvilDragon Moderator Posts: 1,022 mod

    If you store the preset name in a separate string array NKA, then you can also show them on the GUI. At that point it's better to use load/save_array_str().

Back To Top