Solved CONTROL_PAR_PICTURE_STATE Not working...

Discussion in 'Scripting Workshop' started by Steve Mundane, Aug 16, 2019.

  1. Steve Mundane

    Steve Mundane New Member

    Messages:
    7
    Hi All,
    I am slowly learning my way through different script functions.
    I am doing a simple test to make a different image appear when different keys are pressed.
    I have created a png image with 31 frames and corresponding text file.
    I am using the same txt file and image that I have used in other scripts for buttons which works fine so I think the image and txt file are ok.
    The code below is finding the "modernknobgreen" image but just showing the 1st frame when each of the two keys are pressed.
    I am sure I am missing something simple.
    Any help would be fantastic. Thanks in advance.
    Steve :)

    Code:
    on init
    make_perfview
    
    {label details}
        set_ui_height_px(166)
        declare ui_label $label_1 (0,0)
        set_control_par_str(get_ui_id($label_1),$CONTROL_PAR_PICTURE, "modernknobgreen")
    
        make_persistent($label_1)
        set_control_par(get_ui_id($label_1),$CONTROL_PAR_WIDTH, 32)
        set_control_par(get_ui_id($label_1),$CONTROL_PAR_HEIGHT, 32)
        set_control_par(get_ui_id($label_1),$CONTROL_PAR_POS_X,80)
        set_control_par(get_ui_id($label_1),$CONTROL_PAR_POS_Y,45)
        set_control_par(get_ui_id($label_1),$CONTROL_PAR_TEXT_ALIGNMENT,0)
        set_control_par(get_ui_id($label_1),$CONTROL_PAR_FONT_TYPE,22) 
    end on
    
    {So, as a test I was hoping that when the key 0 is pressed frame 10 of image is shown and when key 1 is pressed frame 20 is shown, but it is just showing frame 1 each time}
    on note
    if ($EVENT_NOTE=0)
    set_control_par_str(get_ui_id($label_1),$CONTROL_PAR_PICTURE_STATE,10)
    end if
    if ($EVENT_NOTE=1)
    set_control_par_str(get_ui_id($label_1),$CONTROL_PAR_PICTURE_STATE,20)
    end if
    end on
     
  2. EvilDragon

    EvilDragon Moderator Moderator

    Messages:
    15,059
    Are you absolutely sure the .txt file is correct? Horizontal animation or vertical set up? One empty row at the end of .txt file added?
     
  3. Steve Mundane

    Steve Mundane New Member

    Messages:
    7
    Hi EvilDragon, thanks for your quick reply. Most appreciated.
    So, I assume the code looks ok?
    This is the text file, I use it regularly for buttons.

    Has Alpha Channel: yes
    Number of Animations: 31
    Horizontal Animation: no
    Vertical Resizable: no
    Horizontal Resizable: no
    Fixed Top: 0
    Fixed Bottom: 0
    Fixed Left: 0
    Fixed Right: 0
    (with blank line)

    I am not sure what the issue is?
    I guess I could try a different test image with just 2 frames, keep it simple, and see if that works.
    I'll try that and report back.
    Thanks for your help so far.
    Steve :)
     
  4. Steve Mundane

    Steve Mundane New Member

    Messages:
    7
    So, I have just tried it with a simple stitched png file of 2 images, changed the txt file to 2 animations and it still doesn't work.
    It just shows the first frame on both key presses.
    Any ideas? I'm stumped as to why it is not working. I am sure I am missing something somewhere!
    Steve :)
     
  5. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    524
    Just remove the word str for the PICTURE_STATE command, simply .

    set_control_par(get_ui_id($label_1),$CONTROL_PAR_PICTURE_STATE,10)
     
  6. EvilDragon

    EvilDragon Moderator Moderator

    Messages:
    15,059
    Oh, right. Setting the picture state you just need to use set_control_par(), not set_control_par_str().
     
  7. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    524
    And this kind of small mistake is never reported by the KSP editor. :(
     
  8. EvilDragon

    EvilDragon Moderator Moderator

    Messages:
    15,059
    Because it's not a syntax error, really.
     
  9. Steve Mundane

    Steve Mundane New Member

    Messages:
    7
    Awesome, thanks guys. It works now.
    Yes I had just copied the line from the text label above and didn't notice the str! Doh!
    Thanks for you help.
    Much appreciated.
    Steve :)
     
  10. Steve Mundane

    Steve Mundane New Member

    Messages:
    7
    Hi All,
    So I have been trying to extend the idea and would like the velocity of the note pressed to control the image frame displayed.
    Is it just a case of adding in an EVENT_$VELOCITY=1 or 2 or 3 etc.. to the if statement?
    I have tried several things but none are working. Or do I have to get the velocity parameters in some way using get_control_par or something similar? I am trying to work stuff out and research/test myself before bombarding you guys with easy noob questions.
    I know these are relatively simple things, I appreciate your help as I am learning.
    Steve :)

    Code:
    on note
    if ($EVENT_NOTE=0) {Can I add to this if statement an EVENT_$VELOCITY =X or something like that so the PICTURE_STATE only triggers on certain velocities?}
    set_control_par_(get_ui_id($label_1),$CONTROL_PAR_PICTURE_STATE,10)
    end if
    end on
     
  11. EvilDragon

    EvilDragon Moderator Moderator

    Messages:
    15,059
    Yes, you can merge conditions by using "and" and "or" keywords. See KSP reference.