String vs string

I am honestly just curious… when working on the challenge for this to create a string and an int, why is it that when you create a string you have to put String (capital) but as an int or float it is lowercase?

The items in lowercase are the variable types recognized (int, float…) and the ones with initial uppercase are objects which provide additional funcionalities (e.g. conversions).

1 Like

I meant specifically with the String though.
Why does String have to be capitalized when I am just setting a variable type while int and float do not?

I’m pretty sure what it boils down to is that String is a bit of a programming tomato - fruit, or vegetable? We tend to think of it as being a direct counterpart to things like ints and bools, and it is, but in terms of the functionality available to it, it’s closer to a full-blown object class than an atomic datatype.

You’re definitely not the only one wondering though; if you look closely, String doesn’t even have the same shade of green in the Scripting Workspace as, for example, PackedScene or another such object datatype; its shade matches that of the atomic datatypes like int etc… That suggests to me (by no means confirmed I should add) that even some of the engine contributors see String as a weird outlier that “doesn’t quite fit the mould,” so to speak. Hopefully that provides you with at least a little closure on this =)

The background point is C does not have an idea of what a string is. In fact, it uses arrays of chars (and well, dealing with them is something I don’t miss at all). But since we people don’t like to use that (and “older” programming languages already provided friendlier solutions), there is a class System.String that behaves as everyone expects with strings. Then there are aliases that refer to that class as “string” and “String” depending on what framework you are working with. In this case, “String” is what you should use to refer to it (not that I know Godot, just a C/C++ programmer here).

1 Like

This is a much more complete answer than my own; thanks for the background =)

1 Like

Privacy & Terms