-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integer to string casting and more string blocks #351
Comments
The types relationship (previously named cast_relationships) tell which type can be used in the context of another type. For example, integers and floats are exchangeable. And in particular, all other types can be used in boolean context: `if not Color.BLACK:` is allowed in GDScript as Color.BLACK is falsey. Same for the empty string, zero number, etc. This fixes a bug where an integer or float value block was allowed to be snapped into a string slot. This removes outdated custom casting code that has been abandoned. #351
First off, let's fix the bug. PR #352 addresses the issue seen in the video. On top of that, more text blocks would be welcome. Here is my attempt at "to string" which works with integers and floats. Ideally we would allow any type in its slot. I guess we could make the parameter type optional in
|
@manuq Based on your attempt, here's my version, which is closer to what I envisioned: I like the idea of conveniently accepting any type, and in contrast, my version can limit what type can be accepted. I don't know if there would be a reason for that, which is why I'm leaning towards your version. Here's the branch with my version if you want to look at it: https://github.com/DoomTas3r/changes-block-coding/tree/to-string-block |
Code_It_All made this video using version 0.8.0, but could not cast an integer to a string.
Perhaps make all string parameters accept only strings or improve implicit casting

Parser Error: Value of type "int" cannot be assigned to a variable of type "String".
A Text category could be added for these string-related blocks:
(float) to string
length of (string)
letter (integer) of (string)
And maybe more complex blocks:
replace (string1) with (string2) in (string3)
slice (integer) of (string1) split by (string2)
And finally, the concat block's label could change to differentiate from the add block, for example:
join (string1) (string2)
The current concat block allows both strings and integers to be added, but it compiles to

string + integer
, which produces an errorParser Error: Invalid operands "String" and "int" for "+" operator.
The text was updated successfully, but these errors were encountered: