What does the expression "ToString" mean?

Hi,

I practice with the tutorials in the documentation. I realize, and I had already seen this elsewhere, that we often use the expression “ToString”. I don’t understand it. What does it mean, is there an equivalent in French?

As you can see in the image, here it is used twice. But why? I can’t directly put “Shape” randominrange()?

Thanks for your clarification :pray:

PS: 2nd anecdotal question, what is the difference between RandomInRange and RandomFloatInRange?

ToString returns a text or string version of a number. To keep it very simple, a number is stored as its value in memory. A text version of that number has the ASCII value of it stored in memory.

So the value 1 as a number is stored as 1. But “1” as a character is stored as its ASCII value, 49.

So in the examples you’ve shown, the + operator has different functions depending on the data type being added; for numbers it adds the values. For strings, it appends the values.

If you didn’t have the ToString() in there, then the “+” function would be ambiguous. Are you adding up a string and the number or appending a string and the number? By converting the number to a string, that ambiguity is removed. Also, you can’t set a number to a text. It needs to be converted.

No, because the function RandomInRange returns a number, and you cannot append a number to a string without a conversion.


RandomInRange returns an integer - a number without a decimal place (e.g. -2, -1, 0, 1, 2 etc).
RandomFloatInRange returns a float, which is a number with the decimal place (e.g. 3.14159).

2 Likes

I see, there is some knowledge to be had beyond Gdevelop.

:pray: Thanks for the detailed explanations. I think I’ll understand more easily now.

Have a good day