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.

What type of data can be sent using the IGC.SendBroadcastMessage() function?

Discussion in 'Programming (In-game)' started by Eriksonn, Mar 13, 2019.

  1. Eriksonn Trainee Engineer

    Messages:
    5
    I want to send a bunch of different types of data in a single message but i dont want to make a string out of it.
    I tried to do this:
    Code:
    if (Laser.Status == MyLaserAntennaStatus.Connected)
      {
      object Obj1 = new double[] { OrbitalPeriod };
      object Obj2 = HeightMap;
      object[] Data = new object[]{Obj1,Obj2};
      IGC.SendBroadcastMessage("Sattelite", Data);//Crashes here "Message type object[] is not allowed"
      HeightMap.Clear();
      Laser.Enabled = false;
      }
    I also tried doing
    Code:
    object[] as object
    but that didnt work either…

    So what can i send other than plain strings?

    I am making a sattelite orbiter script and want to have it be more useful by scanning the ground and reporting back to base with anything strage it might find
     
  2. Malware Master Engineer

    Messages:
    9,285
    MyTuples, Immutables (stuff in the Microsoft Immutable namespace) , strings and primitives... No custom types because the receiving PB has no way of understanding that.

    The first thing to understand is that it cannot send any mutable reference type. That would break the separation, allowing you to directly communicate between code regardless of antenna or distance, so no such values år allowed.
     
    Last edited: Mar 14, 2019
  3. Eriksonn Trainee Engineer

    Messages:
    5
    Ah. I knew it could do string but i didnt want to pack and unpack doubles with ToString() and TryParse() as then i would have needed to put some separator character in between and split on those and it would be horrible.(not really but still)
    However as i am now more familiar with string-to-bytes-to-numbers conversion as i have previously needed to extract data from text files. I used BitConverter to take floats(didnt need all the double presicion anyways) to 4 bytes, and then stack those in a byte array and then convert that to chars and then to a string. Works like a charm. Unpacking is alot easier as every number is exactly 4 bytes long, no separators needed.(apart from between different chunks of data but that is fine)

    There was also a hilarious bug as i thought it could auto-convert a byte array into a string as i knew that strings are arrays of chars and chars are essentially bytes and the compiler was fine with it, but it could not. I was sending a single float to test it but the number that arrived was way wrong(~10^30 rather than 0.3) and it was becauce the string was litterally "byte[]". :D
     
  4. Malware Master Engineer

    Messages:
    9,285
    You don't need to use bit conversion. Floats and doubles are primitives.

    Strings are not arrays of chars, they contain an array of chars (but probably not actually stored that way). A char is also not a byte but a ushort (because unicode).
     
  5. Eriksonn Trainee Engineer

    Messages:
    5
    I know that i could just send the whole float but i wanted to convert to string as i actually want to send several floats and float arrays and strings in the same message. It was more of a test that my float-to-string and string-to-float system worked. And what i ment by byte to char is that (byte)'a' is valid
     
  6. Malware Master Engineer

    Messages:
    9,285
    As is (byte)(ushort)10 :) with the new api and the mentioned structures you can send multiple values, even arrays of values, at the same time without any parsing. It's quite the improvement of the old way, easier to deal with and much more performant.
     
  7. Ronin1973 Master Engineer

    Messages:
    4,532

    Can you create a new thread and demonstrate this improvement? Your tutorials are invaluable to us noobs.
     
  8. Eriksonn Trainee Engineer

    Messages:
    5
    So i could send a whole array. Huh… But as i still want to send multiple diffenent types of things(strings,float[] and maybe some more) in the same message i have to turn it into a string right? Becauce if i understand correctly i can only receave once per tick so even if i could send an array i would have do do a separate transmission for each data type and receive them after each other, and that seems harder than what i am doing right now. But maybe i am wrong about how all thins works…
     
  9. Malware Master Engineer

    Messages:
    9,285
    Nope, you don't need separate transmissions ;)

    Would you believe... because I haven't actually used it yet? :p I'll probably add a tutorial to my wiki at some point, but... the fact is, I rarely have use for transmissions. I have a good inkling of how it works, of its capabilities, but I don't want to actually make a tutorial before I've used all aspects of it :D
     
  10. Ronin1973 Master Engineer

    Messages:
    4,532

    Well, thank you in advance (again) for putting your own personal time into this. It truly is appreciated.
     
  11. Eriksonn Trainee Engineer

    Messages:
    5
    So how do i send more than one thing at once? Like if i want to send a float[] and the text "Hello" at the same time?
     
  12. Malware Master Engineer

    Messages:
    9,285
    Combine ImmutableArrays and MyTuple's. I'm sorry, I can't show you an exact example because I don't have access to the game here.