public static IEnumerable <IMyBroadcastListener> GetBroadcastListeners(this IMyIntergridCommunicationSystem src) { var temp = new List <IMyBroadcastListener>(); src.GetBroadcastListeners(temp); return(temp); }
public static void UnregisterBroadcastListener(this IMyIntergridCommunicationSystem src, string tag) { var listeners = src.GetBroadcastListeners(); var taggedListener = listeners.FirstOrDefault(l => l.Tag == tag); if (taggedListener == null) { return; } src.DisableBroadcastListener(taggedListener); }
public List <String> RecieveMessages() { List <IMyBroadcastListener> listeners = new List <IMyBroadcastListener>(); // The method argument below is the list we wish IGC to populate with all Listeners we've made. // Our Listener will be at index 0, since it's the only one we've made so far. IGC.GetBroadcastListeners(listeners); incomingMessages.Clear(); if (listeners[0].HasPendingMessage) { // Let's create a variable for our new message. // Remember, messages have the type MyIGCMessage. MyIGCMessage message = new MyIGCMessage(); // Time to get our message from our Listener (at index 0 of our Listener list). // We do this with the following method: message = listeners[0].AcceptMessage(); if (message.Data != null) { // A message is a struct of 3 variables. To read the actual data, // we access the Data field, convert it to type string (unboxing), // and store it in the variable messagetext. string messagetext = message.Data.ToString(); // We can also access the tag that the message was sent with. string messagetag = message.Tag; //Here we store the "address" to the Programmable Block (our friend's) that sent the message. long sender = message.Source; //Do something with the information! incomingMessages.Add(messagetext); } } return(incomingMessages); }