r/Kos • • Sep 30 '18

[help] Que thy h*ck does this code not work?

It was working then I added something and it stopped... https://pastebin.com/k4JLKqyV The rocket wont pitch and the boosters wont even seperate.

0 Upvotes

4 comments sorted by

4

u/ElWanderer_KSP Programmer Sep 30 '18

Your pitch() function doesn't return until p is less than 5, which I assume takes ages. That means it'll won't reach the lock steering command (or anything else for that matter) within the then block until a long time into flight.

1

u/Ashencloud Sep 30 '18 edited Sep 30 '18

so what can I do? EDIT: so if this is the case then why does boostersep() not work and also in the until p < 5 {} wouldnt that continuously run the code until p<5 meaning that p is changed constantly allowing for gravityturn() to use it?

3

u/ElWanderer_KSP Programmer Sep 30 '18

so what can I do?

You want to avoid combining code that is called every loop with long wait/until statements. Currently, your code doesn't get to boostersep() because it is stuck waiting in the pitch function.

So, how about setting up p as a global variable and locking steering to it once at the start of your launch sequence. You could lock p to a function that calculates it based on the current altitude/velocity (just make sure it has no waits or untold). That way, it'll be called each physics tick and won't block other things in your loop (i.e. boostersep()) from running.

1

u/Ashencloud Sep 30 '18

ended up finding a way but thanks for the advice other than tweaking the speed of the turn its pretty much done. https://pastebin.com/yDjnh5xm