Code Monkey home page Code Monkey logo

Comments (5)

Noiredd avatar Noiredd commented on July 22, 2024 1

We have two problems here. First the obvious one that you noticed: we can't execute an expression referring a symbol that was not defined yet. Solution is seemingly easy: we simply have to define the delegate prior to running PEGAS. I don't know what's the structure of your code, but certainly you don't have to modify pegas.ks (nor should you, really). The way I do it, is to put everything in the boot file.

However, that only solves the problem partially. The second issue is due to some restrictions that kOS places on how you can use delegates, most importantly it prevents you from running a delegate in a different module than it was declared in. In simple terms, this means that if you define your delegate in, let's say, your boot file (and also put it into sequence there), and after that type run pegas. into console, it won't work - because "you typing something into console" and "your previously executed bootfile" are two separate scopes.

The practical solution is to define the delegate and run PEGAS from the same scope, be it your boot file or a regular script file that you execute from the console level.

Hope that helps!

from pegas.

Tonas1997 avatar Tonas1997 commented on July 22, 2024

Hmm, so there are two solutions (correct me if I'm wrong):

  1. Declare the delegate on my boot file and append these instructions to it:
RUN mission.
RUN pegas.

which doesn't allow me to control when the mission "starts" by delaying the execution of PEGAS, or

  1. Create a separate script that has the delegate definition and runs PEGAS, which wouldn't allow me to call the delegate from within sequence.

None of these seem ideal unless I could append to sequence from the separate script in option 2... right?

from pegas.

Patrykz94 avatar Patrykz94 commented on July 22, 2024

I'm pretty sure it would work with the way I use PEGAS.

My vehicle/sequence script is my boot script and in the beginning, before anything else runs, it brings up the terminal window, shows a message on the screen and waits for user input (I need to focus the terminal and press any key for it to continue).

Then it runs the mission file, displays mission parameters on the terminal (it's a good place to verify that I didn't screw something up with the mission) and waits for user input again.

After that, it runs pegas itself. So with this, it will effectively continously be executing from your boot file, while not forcing you to load mission and pegas immediately and it should hopefully let it use the delegate if I understand it correctly.

As for the terminal input code, here's the documentation on that: https://ksp-kos.github.io/KOS/structures/misc/terminalinput.html
But you could use an action group as a trigger instead.

from pegas.

Tonas1997 avatar Tonas1997 commented on July 22, 2024

Ohh, so it's possible to condense everything in the boot file! I'll try and do that myself 😄

from pegas.

Noiredd avatar Noiredd commented on July 22, 2024
  1. Create a separate script that has the delegate definition and runs PEGAS, which wouldn't allow me to call the delegate from within sequence.

But you still can append (or, more likely, insert) to sequence in this option:

FUNCTION shutvents {
  // do stuff
}
sequence:INSERT(
  0,
  LEXICON("time", -25, "type", "delegate", "function", shutvents@, "message", "Shutting down vapor vents")
).
RUN pegas.

I have done it this way on occasion - you just need to be mindful where to insert the delegate event.

I kind of like Patryk's solution, but one significant issue with it is that you cannot alter the execution state this way - it only gives you delays on executing the whole thing, but you can't interrupt it to make some changes. Not the way you could in a usual scheme, where you can execute arbitrary commands after the boot file loads but before running PEGAS.

This is a mildly annoying thing to have to hack around, but some kOS fundamental limitations are like that.

from pegas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.