Can't compare strings (sorry am noob)
stefduijkers opened this issue · 1 comments
stefduijkers commented
Hi there,
I want to send a particular message if the message the arduino sends to unity is "Broken".
I'm just running some simple tests and have this code on the arduino:
switch (Serial.read())
{
case 'A':
Serial.println("Broken");
break;
}
So when i press A in Unity the message "Broken" will be sent back.
I want a response to that message to i put this code in Unity.
void OnMessageArrived(string msg)
{
Debug.Log(msg);
if(msg == "Broken") {
Debug.Log("It's broken y'all");
}
}
The "Broken" message gets logged but the message that should follow it ("It's broken y'all"), doesn't.
I know this is probably simple but i'm really new at programming.
dwilches commented
Hello,
It's possible the value inside of the msg variable has some extra
characters that are not printable (invisible). So they a look at its
length, and call "trim" in case you get an unexpected length.
Regards
…On Tue, Apr 26, 2022, 7:10 AM stefduijkers ***@***.***> wrote:
Hi there,
I want to send a particular message if the message the arduino sends to
unity is "Broken".
I'm just running some simple tests and have this code on the arduino:
switch (Serial.read())
{
case 'A':
Serial.println("Broken");
break;
}
So when i press A in Unity the message "Broken" will be sent back.
I want a response to that message to i put this code in Unity.
void OnMessageArrived(string msg)
{
Debug.Log(msg);
if(msg == "Broken") {
Debug.Log("It's broken y'all");
}
}
The "Broken" message gets logged but the message that should follow it
("It's broken y'all"), doesn't.
I know this is probably simple but i'm really new at programming.
Thanks for the help
[image: Schermafbeelding 2022-04-26 om 14 09 56]
<https://user-images.githubusercontent.com/65162228/165296979-df0a90f9-9081-417e-be9d-aa53d23e69bf.png>
!
—
Reply to this email directly, view it on GitHub
<#61>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA6KR2OCFYH6DFTOC7ZG6QDVG7MM7ANCNFSM5ULUL7FA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>