public override void OnReceivedBroadcast(string fromAddress, string data)
{
OnServerDetected(fromAddress.Split(':')[3], data);
}
I didn’t find any documentation on String.split .
public override void OnReceivedBroadcast(string fromAddress, string data)
{
OnServerDetected(fromAddress.Split(':')[3], data);
}
I didn’t find any documentation on String.split .
What do you mean?
Are you asking about the parameters being passed?
That is the docs for String.split.
The fromAddress.Split(‘:’)[3] term is getting the element at index 3 from a string that is split using ‘:’ as the delimiter
So what will that print out?
You mean specifically regarding that line of code? If so, as per previous post, the value the element at index 3 from a string that is split using ‘:’ as the delimiter. (Note: this is the value that the expression will contain, this has nothing to do with printing anything out - this is just the value that is passed as the first argument to OnServerDetected)
What it exactly contains depends on the string sent.
As a simple example:
string example = "This:is:a:simple:example";
string demo = example.Split(':')[3];
//demo now contains "simple"
If you dont understand splitting strings, here is a brief tutorial
What exactly are you trying to understand? The entire code block or just the splitting of the string?
From context, the code block is passing a portion of the server address and the full message data to an event.
Thanks a lot, the fromAdress string stored an IP address, so using split returned the last digit of the IP address.
As was sort of implied in a previous post by @MickM , whenever you have (or want) code that is not part of Unity’s API, you can find it in Microsoft’s docs. For other examples, you can often find those in searches, too.
Unity documentation is way better than Microsoft, for beginners. I tried to find it on Microsoft website but I didn’t find the actual usage as in an example.
Sure, that can often be true. I’m talking about things that aren’t covered here. Perhaps the microsoft docs didn’t quite make sense when you looked at them (that can happen )
Anyways, it’s just something to keep in mind, but you said you did try there, so you already knew… which is cool.
A bit part of game dev/programming is research. Most problems you encounter have been encountered by many people before you. Getting comfortable with hunting down resources and solutions is something that will pay off in the end.
Something like this is pretty simple.
eg. First result for googling “c# string split tutorial”
http://csharp.net-informations.com/string/csharp-string-split.htm
People like to help but are more willing if you demonstrate you try and help yourself but also - if it takes a few hours for someone to reply… you dont want to be stuck dead for that long eh!