KSP SCRIPT WARNING, help please!

leon59
leon59 Member Posts: 32 Member
edited February 2023 in Scripting Workshop

Hello,

I am new to KSP but I cannot seem to find the answer to this problem I am having in the KSP manual or online. If somebody could assist I would be most grateful. Thank you

I have a menu with left and right scroll buttons. 128 groups. If I press the left arrow / button when group 1 is selected or the right button when group 128 is selected I get this script warning. " SCRIPT WARINING ( Line: xxxx, Script : 0): Invalid ui_menu value! Assignment has no effect. My question is why and how do I stop this from happening?

Comments

  • Gablux
    Gablux Member Posts: 71 Member

    It looks like you forgot to treat those cases in your logic.

    If you decrease the menu value counter forever, soon enough you will hit a number that is not there. Same for increasing the value of the counter.

    Resolved with a simple conditional statement like (pseudo-code)

    dec(counter)
    if counter < min_menu_value then min_menu_value - min_menu_value
    

    same for the increasing side.

  • leon59
    leon59 Member Posts: 32 Member

    Hi Gablux,

    Thank you for your reply. I get the idea but I'm not quite sure where this code goes. Is it under $PrevMenu := 0 ie: if($PrevMenu1 < 0 then 0 - 0). Sorry but like I say I'm really new to all of this but, this is the last issue as far as I can tell with my custom instrument which has taken me a couple of weeks to code from scratch ( with the help of many great posts in the forums :) )

    on ui_control($PrevMenu1)
    $menu1 := (get_control_par(get_ui_id($menu1),$CONTROL_PAR_NUM_ITEMS)+$menu1-1) mod get_control_par(get_ui_id($menu1),$CONTROL_PAR_NUM_ITEMS)
    $PrevMenu1 := 0
    $i := $LAYER1_FIRST
    while ($i<=$LAYER1_LAST)
    purge_group($i,0)
    inc($i)
    end while
    purge_group($menu1,1)
    purge_group($menu2,1)
    end on
    


  • leon59
    leon59 Member Posts: 32 Member

    Ok managed to sort it out. Thank you.

Back To Top