I couldn't figure out how to receive String form text inside a procedure. I don't exactly even know how to call that situation so i wish someone understands from my explanation
Example situation:
void Process(int X, int Y, String Message) {
Serial.println(Message);
}
^ Example was called: Process(3,9,"Number " + Number);
however, that returns me an error.
I figured out, that i can send text if i declare the Message to be char*
Although, i will be facing an error again if i try to combine "Number" + Number.
Post some real code, if you want us to help. There is nothing obviously wrong with the Process() function, except the use of the String class. The call to the function has some problems, since "Number " + Number is not a String. It could (but shouldn't) be coerced into being a String.
Lets put it like this. The procedure i want to call, is a sort of a parsing system for a message. Basically, it will display the message the procedure receives, and it maybe numbers, characters or mixed. I don't think there will be the code you requested as it serves no need.
The reformed question :
How should i declare the Message variant in the Process void, to be able to use it to "receive" Strings, Strings + Numbers (coerced into being a String) or just Numbers ? = ANYTHING
How should i declare the Message variant in the Process void
First, Process is a function, not a void. Second, C++ is a strongly typed language. There are no Variant types. You must EXPLICITLY define the type of all arguments to the function.
Now, if the function is a class method, then you can use function overloading, like the Print class does, to have several functions with the same name (print()) that take different argument types.
However, you can't parse a number. You can only parse strings. So, it only makes sense to define the function to take a string (a NULL terminated array of chars) and then always calls the function with a string.
PaulS:
You must EXPLICITLY define the type of all arguments to the function.
Yes, thanks. And what is the explicitly defined type of String ? If int X is the correct for a number what is correct definition for the string ?
And i highly respect your willing to guide me also in something i didn't even ask, but still, i would love to hear the exact answer. Not knowing that is the only thing holding me in square one.
Please, don't try to think how my code works outside my question. Please just answer how can i send this text: "Number: " and then add an integer of the number array with it, into a function as a string. After it, the received string should look like Number: 0
Yes, thanks. And what is the explicitly defined type of String ? If int X is the correct for a number what is correct definition for the string ?
String or string? A string is a char array that is properly NULL terminated. A String is a class.
Please just answer how can i send this text: "Number: " and then add an integer of the number array with it, into a function as a string. After it, the received string should look like Number: 0