Custom functions and ksp_builtins_data.py issues

magneto538

KSP Developer
Hello people.

I am working at a custom library of functions for KSP developers. It's quite a massive job which took 9 months of work so far.
So I'd love to add my custom functions and macros to ksp_builtins_data.py in order to speed up the workflow.

Here's my problem. When I add a function under [functions] section in ksp_builtins_data.py, the script compiles correctly in SublimeKSP, but when I paste it into Kontakt I see that my custom functions - which I do not call using "call <function>" - are not "unpacked" properly.

Example

Code:
{I declare a custom function here}
function resize_ctrl(ui_id, w, h)
    {...}
end function

{Now I call this function somewhere by using this syntax}
on ui_control (button)
    resize_ctrl(get_ui_id(button), 20*button, 15*button)
end on
Inside ksp_builtins_data.py, under [functions], I have the list of all the native KSP functions. I want to add my own functions here in order to get auto-complete and stuff.

Code:
[functions]
END_USE_CODE()
RESET_CONDITIONS(<condition>)
RESET_CONDITION(<condition>)
...
resize_ctrl(<ui-id>,<w>,<h>)
The problem is: when I call resize_ctrl as I do (without writing "call" instruction) in on ui_control callback, the content of resize_ctrl's declaration should replace the function call (as if it was a macro). If I add resize_ctrl to ksp_builtins_data.py, though, this won't happen anymore, so I get an error because I have the call to resize_ctrl without having its declaration anywhere.

I am going crazy here. What am I doing wrong?
 

EvilDragon

KSP Wizard
I don't think SublimeKSP, the way Nils wrote it, supports what you want to do... "Extra syntax checks" option depends on tokens used in function arguments (<ui-id>, stuff like that), so I'm not sure if inventing your own tokens here is doing it any good.

That said, I think it's not enough to add your functions to ksp_builtins_data.py is enough. You also need to add them to KSP.tmLanguage, so syntax coloring works. But overall, the proper way of using custom libraries is only by using the "import" keyword. Any hacks to other compiler related files might just mess stuff up...
 

Lindon

VST/AU Developer
yeah I thought about doing this sort of thing, but after a brief investigation it became clear that it wasn't the way to go so I wrote a KSP generator in Kivy/Python that takes the native skinman file and write s the entire KSP UI...tabs radio buttons and all...
 
OP
magneto538

magneto538

KSP Developer
I don't think SublimeKSP, the way Nils wrote it, supports what you want to do... "Extra syntax checks" option depends on tokens used in function arguments (<ui-id>, stuff like that), so I'm not sure if inventing your own tokens here is doing it any good.

That said, I think it's not enough to add your functions to ksp_builtins_data.py is enough. You also need to add them to KSP.tmLanguage, so syntax coloring works. But overall, the proper way of using custom libraries is only by using the "import" keyword. Any hacks to other compiler related files might just mess stuff up...
Yeah, I already added everything to KSP.tmLanguage, I forgot to mention that.
Sad news, though. I was really hoping to speed up a lot the workflow, as my library has a great amount of functions. But if you need to go and check the correct syntax on the manual everytime you need to write something, then the workflow wouldn't be so optimized...

Anyways, it seems that macros do not suffer from this issue. I have a few custom macros and I added them under [functions]. They work as expected, so I have auto-complete, coloring and they are also compiled as they are meant to. The problem here seems to be only with functions.