What's new

KSP: any insight into this mysterious bug?

OP
Fredeke

Fredeke

Senior Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #43
Ok, after a pause to let my brain cool off, I'm tackling this again.

I've been following advices, but I can't manage to read NKAs right.

Here's the bit of my code dealing with that:
Code:
on persistence_changed
  if (NKA_SAVE = 0)
    load_array (_drone_pitch, 2)
    load_array (_drone_type, 2)
    load_array (_drone_defTk, 2)
    load_array (_track_gp, 2)
    load_array_str (_track_name, get_folder ($GET_FOLDER_PATCH_DIR) & "/Data/_track_name.nka")
    load_array_str (_drone_name, get_folder ($GET_FOLDER_PATCH_DIR) & "/Data/_drone_name.nka")
    load_array_str (_drone_group, get_folder ($GET_FOLDER_PATCH_DIR) & "/Data/_drone_group.nka")
    print (num_elements (!_drone_name))
    for $i := 0 to num_elements (!_drone_name) -1
      print ($i & ":  " & !_drone_name [$i])
    end for
  end if
  iterate_macro (clear_mixer_tracks) := 1 to 6         // not
  call update_source                                                   // really
  call toggle_panels                                                      // relevant
end on

on ui_control ($bt_save)
  save_array (_drone_pitch, 1)
  save_array (_drone_type, 1)
  save_array (_drone_defTk, 1)
  save_array (_track_gp, 1)
  save_array_str (_track_name, get_folder ($GET_FOLDER_PATCH_DIR) & "/Data/_track_name.nka")
  save_array_str (_drone_name, get_folder ($GET_FOLDER_PATCH_DIR) & "/Data/_drone_name.nka")
  save_array_str (_drone_group, get_folder ($GET_FOLDER_PATCH_DIR) & "/Data/_drone_group.nka")
  print (num_elements (!_drone_name))
  for $i := 0 to num_elements (!_drone_name) -1
    print ($i & ":  " & !_drone_name [$i])
  end for
end on

The idea is to save the arrays that were already populated in KSP to NKAs, then comment out the populating part (to releive the parser, which was running its stack too close to the limit), leaving only array declarations, and load the content from the NKAs instead.

Only, when I load the string NKAs, they appear to be just full of zeroes or empty strings. Er... Like they didn't load and are still as just declared.

According to the debugger, the arrays' content is right before saving, but it's not after loading. The content of the files looks fine in a text editor, so the error must happen at loading. It is the same regardless of type, string or integer.

Can you see anything wrong with the code ?
 
Last edited:
OP
Fredeke

Fredeke

Senior Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #45
Mmh... I'm such a noob. I did know that but I forgot. (probably let my brain cool off too much)

The doc says load_array is synchronous when used in the ICB (though we should mind persistence issues). So I tried that because it was simpler, and I only need to load them once at instrument launch anyway.

It half worked: now some arrays load, others still don't.

I know it looks like the problematic arrays are persistent, but they're not. In fact, it's more like string arrays get loaded, but not integer arrays. Puzzling...

I don't suppose all those arrays being declared as multi-dimensional in sKSP has anything to do with this?
 
Last edited:

EvilDragon

KSP Wizard
If you're loading from ICB, you need to first read_persistent_var on all those arrays, then load_array.

I haven't yet stumbled upon a case where this didn't work.
 
OP
Fredeke

Fredeke

Senior Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #47
If you're loading from ICB, you need to first read_persistent_var on all those arrays, then load_array.

I haven't yet stumbled upon a case where this didn't work.
I've followed your advice for the sake of trying everything, but since none of these arrays are persistent, it didn't solve anything.

Then I figured I should use mode 1 instead of mode 2 for load_array: surely it would never work trying to load from the wrong place! But even after correcting this, integer arrays still don't load.
 
OP
Fredeke

Fredeke

Senior Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #49
I want to load from the Data folder, located alongside the Resources folder and resources container (see the path for string arrays, which now load perfectly).

That's mode 1, right?

Mode 2 would load from inside the .nkr container file... Right?

This is a tad confusing, I must admit.
 

EvilDragon

KSP Wizard
Yeah if you're loading from Data folder outside of Resources folder, then you should use mode 1 everywhere.
 
OP
Fredeke

Fredeke

Senior Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #51
Yeah if you're loading from Data folder outside of Resources folder, then you should use mode 1 everywhere.
I'd like this line:
load_array (_drone_pitch, 1)

to load from an nka located just alongside this other one:
load_array_str (_drone_name, get_folder ($GET_FOLDER_PATCH_DIR) & "/Data/_drone_name.nka")

Is there anything wrong in these two lines, that would make them try to load from different folders?
 
Last edited:

EvilDragon

KSP Wizard
You might as well use load_array_str() for all those arrays then?

You can always check if your load command is correct by doing it from a button's UI callback, then checking $NI_ASYNC_EXIT_STATUS in async_complete callback.
 
OP
Fredeke

Fredeke

Senior Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #53
You might as well use load_array_str() for all those arrays then?
You mean load everything as string arrays, and then copy the relevant ones into integer arrays, with a conversion inside a loop? Sure, that would get me out of the woods fast, but... I don't see a string_to_int() command in the doc... am I not looking hard enough?

You can always check if your load command is correct by doing it from a button's UI callback, then checking $NI_ASYNC_EXIT_STATUS in async_complete callback.
This takes a little more programming... I'll let you know how this turns out if your first trick doesn't work.
 

EvilDragon

KSP Wizard
load_array_str() does NOT mean it's only used for loading string arrays. You can load any NKA with that command. "_str" means it takes a string as argument, the path from which you want the NKA to load. :)
 
OP
Fredeke

Fredeke

Senior Member
Thread starter
  • Thread Starter
  • Thread Starter
  • #55
load_array_str() does NOT mean it's only used for loading string arrays. You can load any NKA with that command. "_str" means it takes a string as argument, the path from which you want the NKA to load. :)
That's great news (in addition to making more sense) !
It should solve the issue.
 

McSound

Member
I had just the same issue. The solution was easy. There're can only be 996 lines In the on init callback. If your code is bigger then do the next trick:

on init
996 lines
if 1=1
next 996 lines
end if
if 1=1
other next 996 lines
end if
end on
 

EvilDragon

KSP Wizard
It depends on what you're doing in your init callback. You can have more than 996 lines in there (I've written larger ones).

Anyways 1=1 is a crutch and you should figure out better ways of initializing your UI widget properties if you're stumbling upon this sort of thing.
 
Top Bottom