Jump to content

SendMessage to active vessel?


Recommended Posts

Again I am stumbling around in the dark not sure why this is not working. I am trying to activate a function in a partmodule in the active vessel from a near by vessel but it is not being activated - see code below;

class mypart: PartModule

{

// Send Message

[KSPEvent(guiActiveUnfocused = true, externalToEVAOnly = false, unfocusedRange = 20f, guiName = "Pair With This Port", active = false)]

public void TestEvent()

{

BroadcastMessage("T1", this);

SendMessage("T2", this);

FlightGlobals.ActiveVessel.BroadcastMessage("T3", this);

FlightGlobals.ActiveVessel.SendMessage("T4", this);

FlightGlobals.ActiveVessel.rootPart.BroadcastMessage("T5", this);

FlightGlobals.ActiveVessel.rootPart.SendMessage("T6", this);

}

// Send Messages

[KSPEvent(guiActive = false, active = true)]

public void T1(object Part)

{

ScreenMessages.PostScreenMessage("T1", 5.0f, ScreenMessageStyle.UPPER_CENTER);

}

[KSPEvent(guiActive = false, active = true)]

public void T2(object Part)

{

ScreenMessages.PostScreenMessage("T2", 5.0f, ScreenMessageStyle.UPPER_CENTER);

}

[KSPEvent(guiActive = false, active = true)]

public void T3(object Part)

{

ScreenMessages.PostScreenMessage("T3", 5.0f, ScreenMessageStyle.UPPER_CENTER);

}

[KSPEvent(guiActive = false, active = true)]

public void T4(object Part)

{

ScreenMessages.PostScreenMessage("T4", 5.0f, ScreenMessageStyle.UPPER_CENTER);

}

[KSPEvent(guiActive = false, active = true)]

public void T5(object Part)

{

ScreenMessages.PostScreenMessage("T5", 5.0f, ScreenMessageStyle.UPPER_CENTER);

}

[KSPEvent(guiActive = false, active = true)]

public void T6(object Part)

{

ScreenMessages.PostScreenMessage("T6", 5.0f, ScreenMessageStyle.UPPER_CENTER);

}

}

Notice that TestEvent is only being triggered from a nearby vessel.

The only thing I get on the screen is T1 and T2. :( What am I doing wrong?

Also, I was wondering if there is a way for a vessel to save some sort of custom meta data?

Link to comment
Share on other sites

ok, I figured it out. For other devs who feel like they are in the dark, looking at KAS plugin source code has really helped me. I am not sure if it is cool to add the link so I will not but it is on github.

For my solution I used a static class to maintain state information. For the SendMessage it seems I had to send to the partmodule and not to the part - I am still not sure the difference between the two things (noob).


public static class MO_Shared
{
public static ModuleDockingNode activeMOPort1 = null;
public static ModuleDockingNode activeMOPort2 = null;

public static List<Dockingv2> GetAllDockingv2sWithState(Vessel fromVessel = null, bool ActiveState = false)
{
...
}
}

...

public class Dockingv2 : ModuleDockingNode
{
...
[KSPEvent(guiActiveUnfocused = true, externalToEVAOnly = false, unfocusedRange = 20f, guiName = "Pair With This Port", active = false)]
public void PairWithPort()
{
...
MO_Shared.activeMOPort1.SendMessage("LinkUp");
...
}
}

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...