What's new

Confused about Save/Load_Array commands


Observant Sound
I'm trying to create a preset system for myself and after reading the KSP manual and some other posts here, my own tests haven't been sucessful.

My logic/plan is this:
1. I create the presets by loading the current values of all my controls in a general purpose preset array, then I save that array to the Data folder with save_array. I then name these files preset1, preset2 etc in the pop-up window
2. At init, I load these arrays with load_array using the names I used when saving them
3. I have several buttons corresponding to the various presets I created and clicking one of these buttons is supposed to read the values of the loaded array (%preset1, %preset2 ...).
4. After clicking that button all the values from that array are supposed to get read and applied to the corresponding controls ([0] = lfo freq 1, [1] = lfo freq 2 etc.)

on ui_control (preset1) load_array(preset1, 0) for i := 0 to num_elements(preset1) - 1 slider_IDs[i] -> VALUE := preset1[i] end for end on

When compiling the code above in sublime, I get the error message that "preset1" has not been defined.
This happens both when the load_array command is in init and/or in the UI callback.
My understanding was that when you load an array, that array is now forever in the system and can be referenced so I don't understand why Sublime tells me it hasn't been defined.

Also in the post above Evil Dragon mentioned using load_array_str instead. From what I understood from the post using load/save_array_str allows you to be more flexible in your naming since you can dynamically choose which preset name nka you want to load.
I don't understand the idea of having a master nka file though. Every save_array command still creates a unique nka does it not?
And what benefit is it to define the file path? Don't I want all my arrays to end up in the Data folder so that the user always has them available no matter where he moves his instrument folder?

Would very much appreciate if you could find the flaw in my logic as I'm not sure how to go about bug testing myself.


Active Member
This could be silly but ... Try making the name for button and preset different. Like presetbtn1 and presetarray1. It could be that since you don’t use $ or % the on ui_control does not know which one it is


Observant Sound
Thread starter
  • Thread Starter
  • Thread Starter
  • #3
Think I figured it out. It's just very finicky about name matching depending on which mode you're using
Top Bottom