Jump to content

How to tell if an engine is active


Recommended Posts

I'm not sure what you are asking, it's just a property of ModuleEngines in my Visual Studio object browser.

In terms of documentation, it's what I use to tell if an engine is firing for my Vertical Velocity mod and it's worked so far. I determined that by testing how it worked myself, there's no reliable documentation beyond what the names indicate, although the KSP API documentation project tries (it's on github), but it does have out of date information on it.

D.

Link to comment
Share on other sites

public bool engineIgnited for if its active.

maxThrust / finalThrust for "percentage" of output.

EngineIgnited might be outdated. May need to test it. Maybe isOperational is now used like others have said.

hope this helps.

Edited by landeTLS
Link to comment
Share on other sites

If I remember right, engineIgnited is true if the engine is trying to fire, isOperational is true when the engine is actually firing.

So if the engine is trying to fire, but flamed out due to lack of fuel, engineIgnited is true while isOperational is false.

I did that test months ago though so double check if you are going to use that property.

D.

Link to comment
Share on other sites

I don't doubt that ModuleEngines.isOperational is what I'm looking for, but I can't figure out how to operate it. How do I pull the status of isOperational from ModuleEngines? Is there a global resource I need as a reference, or a special way I need to define a variable?

Link to comment
Share on other sites

I think this is now getting into more general programming questions, but the absolute basic explaination is:

First, I'm assuming you have your programming IDE setup, including the reference to Assembly-CSharp.

Then, FlightGlobals.ActiveVessel is a static you can use to get the current vessel, the Vessel.parts list is all parts on the vessel, then the Part.modules list is all partModules on that part, a part that is an engine will have a ModuleEngine in that Part.modules list.

Then you can pull the ModuleEngines.isOperational value from there.

Is that more what you were looking for?

D.

Link to comment
Share on other sites

// if you inherit from moduleEngines skip this step
List<ModuleEngines> e = part.Modules.GetModules<ModuleEngines>(); // a collection of all engines in this part
if (e.Any())
{
//if partmodule inherits from module engines (FX), you only need this bit (leaving out e[0])
if (e[0].IsOperational) // if first engine in the part is running
produceHeatAndEC();
}

Edited by Crzyrndm
Link to comment
Share on other sites

There has to be something more fundamental that I'm missing. Here's my error using Crzyrndm's code:

Error 2 'System.Collections.Generic.List<ModuleEngines>' does not contain a definition for 'isOperational' and no extension method 'isOperational' accepting a first argument of type 'System.Collections.Generic.List<ModuleEngines>' could be found (are you missing a using directive or an assembly reference?) C:\Users\Ben\Documents\Visual Studio 2013\Projects\Reactor\Reactor\Class1.cs 41 15 Reactor

Here are my references:

Assembly-CSharp

System

System.Core

System.Data

System.Data.DataSetExtensions

System.Xml

System.Xml.Linq

UnityEngine

Here are my using statements:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using UnityEngine;

using KSP;

Does anyone know what I am missing?

Link to comment
Share on other sites

That sounds like you tried to get .isOperational on the list as a whole (type List<ModuleEngines>) rather than an element of the list (type ModuleEngines). You didn't skip the indexing did you? (e[0] to grab the first element from the list)

Link to comment
Share on other sites

I did skip the index, and that fixed that error, but now I have an object reference error with Part.Modules that I can't seem to fix.

Error 1 An object reference is required for the non-static field, method, or property 'Part.Modules.get'

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...