Welcome to the new and improved Native Instruments online community. Join our active forum of 40,000+ members for discussions and much more.

"Variable not defined" in KSP multi script

Chrycibulum Member Posts: 4 Member
edited November 2022 in Scripting Workshop

Hello, I'm stumped by a compile error in my multi script. This is my first KSP project, and my ultimate goal is to create melody and bass couplers to use with Impact Soundworks' Fredonia Grand Organ. (I don't have the intended behaviour working yet--this script simply splits a keyboard into 3 zones and distributes them across 4 MIDI channels.)

The error is "Error (line 236): variable "$melody_to_out4" was not declared." That variable is defined on line 84, and Notepad++ recognises them as being spelled identically.

All variables are global in KSP, right? I don't understand why the compiler doesn't recognise $melody_to_out4.


  • jmarcv
    jmarcv Member Posts: 9 Member
    edited November 2022

    I am with you. I don't see why either, and it seems the issue is with all of your "on ui_control " variables. I deleted "on ui_control ($melody_to_out4_switch)" block and then it complained about $melody_to_out3, etc.....

    You could eliminate the redundancy of passing the melody_to_out#_switch variable to the melody_to_out# and just use the _switch variable directly. This would eliminate the need for all of your "on ui_control" code and  all the extra declare lines in the init.

  • EvilDragon
    EvilDragon Moderator Posts: 858 mod

    The culprit are these lines:

    You cannot inline declare a variable with a value of another variable - you can only inline declare it with a constant or literal value.

    That said, I don't know why you have these extra variables when you can use values from switches directly? You just need to make them all persistent.

Back To Top