TheUltimateKerbonaut

Members
  • Content count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About TheUltimateKerbonaut

  • Rank
    Newbie

Profile Information

  • Location Isle of Man, UK, Earth
  • Interests KSP, Programming, Game Development.
  1. Hello everyone . I am making my first KSP mod, which simply displays a gui, with a label telling you how much science is stored on a vessel. However, I am stuck on trying to find out how much science is stored in each ModuleScienceContainer or ModuleScienceExperiment. Does someone know how this can be achieved, or is it impossible? Here is my code: using System; using System.Collections.Generic; using UnityEngine; using KspScienceCount.Extensions; using KSP; namespace KspScienceCount { public class ScienceCount : PartModule { private Rect _windowPosition = new Rect(); private GUIStyle _windowStyle, _labelStyle; private bool _hasInitStyles = false; public void OnGUI() { if (!_hasInitStyles) InitStyles(); if (Event.current.type != EventType.Repaint || Event.current.isMouse) { if (this.vessel == FlightGlobals.ActiveVessel && this.part.IsPrimary(this.vessel.parts, this.ClassID)) _windowPosition = GUILayout.Window(10, _windowPosition, OnWindow, "This is a title",_windowStyle); } } private void OnWindow(int windowId) { GUILayout.BeginHorizontal(); GUILayout.Label("Science on this vessel: " + CountScience(), _labelStyle); GUI.DragWindow(); GUILayout.EndHorizontal(); } private void InitStyles() { _windowStyle = new GUIStyle(HighLogic.Skin.window); _windowStyle.fixedWidth = 150f; _labelStyle = new GUIStyle(HighLogic.Skin.label); _labelStyle.stretchWidth = true; _hasInitStyles = true; } private float CountScience() { float count = 0; foreach (Part rocketPart in this.vessel.parts) { foreach (PartModule module in rocketPart.Modules) { if (module.GetComponent<ModuleScienceExperiment>() != null) { for (int i = 0; i == module.GetComponent<ModuleScienceContainer>().GetData().Length - 1; i++) { //count += module.GetComponent<ModuleScienceExperiment>().GetData()[i]. <-- this bit here } } } } return count; } } } Many thanks in advance, TheUltimateKerbonaut