Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Help using new inter-grid communications

Discussion in 'Programming (In-game)' started by Siondrome, Mar 2, 2019.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Siondrome Trainee Engineer

    Messages:
    2
    Can someone explain how the new inter-grid communication system works? The old method of using the "IMyRadioAntenna.TransmitMessage" doesn't seem to work anymore and I can't find any information about the new system. I've been searching through the forums, Malware's API index, and google for any information. The most information I've found was on Malware's API index, but that still left me confused of how to actually use it.

    For reference, when I tried running a script that used the TransmitMessage() function, I get this warning:
    [​IMG]
     
  2. MarcoROG-SG Trainee Engineer

    Messages:
    1
    I'm having the same issue, there is not much documentation about it.
    Nothing on Steam Guides either.
    Hopefully we'll be able to have some code examples!
     
  3. Malware Master Engineer

    Messages:
    9,866
    I haven't actually used the new interface myself yet as I rarely have much use for comms, but there are some examples here. Keep in mind though, these are early samples and might be slightly off - should still point you guys in the right direction, I hope. Otherwise - there's always the #programming-in-game channel in Keen's discord (link on the front page of this forum), people have been learning and using the new system there.
    https://github.com/InflexCZE/SE-InterGridCommunicationProposal/tree/master/SamplePBScripts
     
  4. Siondrome Trainee Engineer

    Messages:
    2
    Thanks! Those examples are just what I needed to get started.
     
  5. Loues S. Cat Apprentice Engineer

    Messages:
    143
    Been mucking about with it.
    This is as far as I have gotten.

    Code:
    public Program() {
    	var comm = IGC.UnicastListener;
    	//comm.SetMessageCallback( myTag );
    	//comm.SetMessageCallback( "Test" );
    	//void DisableMessageCallback(); // no idea yet
    	
    	Runtime.UpdateFrequency = UpdateFrequency.Update100;
    	
    	IMyBroadcastListener listen = IGC.RegisterBroadcastListener( myTag );
    	IGC.RegisterBroadcastListener( "DOGS" );
    }
    
    
    
    public void Save() {
    	
    }
    
    
    
    public string procListens() {
    	StringBuilder sb = new StringBuilder( "___Listen_Log___" ).Append( '\n' );
    	
    	var listens = new List<IMyBroadcastListener>();
    	IGC.GetBroadcastListeners( listens );
    	
    	for( int i=0; i<listens.Count; ++i ) {
    		sb.Append( "  <* Listen: "+ listens[i].Tag ).Append( " *>\n" );
    		while( listens[i].HasPendingMessage ) {
    			var msg = listens[i].AcceptMessage();
    			sb.Append( "  "+ msg.Data.ToString() );
    			if( msg.Data.ToString() == "PING" ) {
    				sb.Append( "  >> Answer: "+ IGC.SendUnicastMessage<string>( msg.Source, msg.Tag, "PONG" ) );
    			}
    			sb.Append( '\n' );
    		}
    	}
    	
    	return sb.ToString();
    }
    
    
    public string procMyMessages() {
    	StringBuilder sb = new StringBuilder( "___PMS_Log___" ).Append( '\n' );
    	
    	var comm = IGC.UnicastListener;
    	
    	sb.Append( "  Has Message: "+ comm.HasPendingMessage ).Append( "\n" ); // bool
    	
    	while( comm.HasPendingMessage ) {
    		MyIGCMessage msg = comm.AcceptMessage(); // object??
    		sb.Append( "  IC " ).Append( msg.Source ).Append( ": (" ).Append( msg.Tag ).Append( ") " ).Append( msg.Data.ToString() ).Append( "\n" );
    		if( msg.Data.ToString() == "PING" ) {
    			sb.Append( "  >>Sent Rep: "+ IGC.SendUnicastMessage<string>( msg.Source, msg.Tag, "PONG" ) ).Append( "\n" );
    		}
    	}
    	
    	return sb.ToString();
    }
    
    
    
    string myTag = "CATS";
    public void Main( string argument, UpdateType updateSource ) {
    	StringBuilder sb = new StringBuilder( "___Comm_Test___" ).Append( '\n' );
    	
    	sb.Append( "  PB Address: " ).Append( IGC.Me ).Append( '\n' );
    	
    	sb.Append( procMyMessages() );
    	
    	sb.Append( procListens() );
    	
    	var rnd = new Random();
    	if( 1 == rnd.Next( 1, 5 ) ) {
    		IGC.SendBroadcastMessage<string>( "DOGS", "Dogs Are Evil" );
    	} else {
    		IGC.SendBroadcastMessage<string>( myTag, "PING" );
    	}
    	
    	display( "Mew", sb.ToString() );
    }
    
    
    public void display( string tag, string text ) {
    	List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
    	GridTerminalSystem.GetBlocksOfType<IMyTextPanel>( blocks, x => x.CustomName.Contains( tag ) ); // get all terminal blocks on primary or secondary grid
    	
    	for( int i=0; i<blocks.Count; ++i ) {
    		(blocks[i] as IMyTextPanel).WritePublicText( text );
    	}
    }
    
     
  6. Ronin1973 Master Engineer

    Messages:
    4,964
    Interesting script. Is it necessary to search for Text Panels with your CustomName tag every time the script wants to write to the panel? Perhaps perform the search when first run and have an argument like "reset" to recalculate the list?
     
Thread Status:
This last post in this thread was made more than 31 days old.