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

Script to locate file in folder

Discussion in 'Scripting Workshop' started by Itariel Bandeira, Apr 11, 2018.

  1. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    Quote from KSP reference:

    "The array data is not directly available after the load_array() command has been executed since the command works asynchronous. The only situation in which the values are instantly available is when using mode 1 or mode 2 within an init callback. "

    Which means using wait() in ICB in this case is useless, array is guaranteed to be loaded when load_array is used in ICB. Meaning, ICB automatically figures out async.
     
  2. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Ok, so I do not need the wait. Script made, however I'm a little lost still as to the file that should contain the values, I do not really understand matrices in kontakt, I need an aid.
     
  3. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    If you don't understand that (and those are basics), you need to learn some programming basics in the first place...
     
  4. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    I'm finding myself here, but I need a light on this auth_array that has been given to me as an example. Will it compare to the information in a correct .nka file? How do I create this file and put this information in it?
     
  5. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    NKA file is just a text file with name of the array in the first line, then numbers of the array below that line (one number per line).
     
  6. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Thank you very much!
     
  7. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    I can not do it or something in the script is wrong. I'm trying to make the notes do not go out when playing if the value is different from .nka.
    Code:
    on init
    
    make_perfview
    set_ui_height_px(350)
    
      declare %teste[4]
      declare $auth_switch := 0
      declare $auth_id
    declare ui_button $teste
      $auth_id := load_array(%teste,1)
    
      if (abs(%teste[0]+%teste[1])=%teste[2])
        if (abs(%teste[0]-%teste[1])=%teste[3])
          $auth_switch := 1
        end if
      end if
    end on
    
    on async_complete
      if ($NI_ASYNC_ID=$auth_id)
        $auth_id := -1
      end if
    end on
    
    on note
      if ($auth_switch=0)
    if ($EVENT_NOTE < 108 or $EVENT_NOTE > 20) {out of range} 
    ignore_event ($EVENT_ID)
        end if
      end if
    end on
    
    My teste.nka:
    %teste
    0
    1
    2
    3
     
  8. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    See:
    Code:
    on init
       
        make_perfview
        set_ui_height_px(350)
       
        declare %teste[3]
        declare $auth_switch := 0
        declare $auth_id
        declare ui_button $ATIVAR
    end on
    
    on ui_control ($ATIVAR)
    $ATIVAR := 1
    load_array(%teste,0)
       
    if (abs(%teste[0]+%teste[1])=%teste[2])
          $auth_switch := 1
        end if
    end on
    
    on note
        if ($auth_switch = 0)
            ignore_event ($EVENT_ID)
        end if
    end on
    
    I managed to get here, now I would like that when selecting the .nka it would save the current state and if it would have like program it to move in the folder structure it requested again the .nka. That would not be 100% but it would help me a lot already
     
  9. Lindon

    Lindon NI Product Owner

    Messages:
    322
    "when selecting the .nka it would save the current state "

    so look up save_array() in the manual...
     
  10. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Well I'm practically scripted the way I want it. I got it this way.
    But I would still like the wallpaper and declarations to only load with auth_switch = 1, otherwise nothing will load.
    This way I can not do it. Any solution?

    Code:
    on init
        declare %teste[3]
        declare $auth_switch 
        declare $auth_id
        declare @basepath
        @basepath := "C:/Windows/System32/uau001.nka"
    
        $auth_id := load_array_str(%teste,@basepath)
    
        if (abs(%teste[0]+%teste[1])=%teste[2])
                $auth_switch := 1
        end if
    
         if ($auth_switch = 1)
         make_perfview
        set_ui_height_px(350)
        end if
    end on
    
    on async_complete
        if ($NI_ASYNC_ID = $auth_id)
            $auth_id := -1
        if ($NI_ASYNC_EXIT_STATUS = 0)
            $auth_switch := 0
        end if
        end if
    end on
    
    on note
        if ($auth_switch = 0)
        ignore_event ($EVENT_ID)
    end if
    end on
    
     
  11. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    You cannot condition make_perfview like that. If it's in the script, it's always going to show the performance view.
     
    Last edited: Apr 18, 2018
  12. Itariel Bandeira

    Itariel Bandeira NI Product Owner

    Messages:
    34
    Evil however if nka exists the value in it is not 0,0,0 it works and the wallpaper is not shown. Now when the file does not exist and depending on the async return it does not work. It seems to be some flaw in the return because without it it worked here and it did not open anything.
     
    Last edited by a moderator: Apr 18, 2018
  13. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    If the file doesn't exist, there's nothing to return really. Then you get the initialized array (0, 0, 0).