-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Exposed randi_range to global funcs + renamed rand_range to randf_range #40718
Conversation
10b2865
to
18576e6
Compare
This change makes sense, except that it would also make sense to go in the other direction, removing methods from global scope. Personally I like having these methods available due to how common they can be in projects, but it's worth a discussion. See also godotengine/godot-proposals#1590 for a discussion about removing the seed methods from global scope. |
a0f3902
to
2b2c756
Compare
@aaronfranke I agreed with both directions, so either we choose one or another - I would be happy, I think @reduz should decide :) |
e7d9c09
to
20d6151
Compare
a1db728
to
a368071
Compare
MATH_RANDF_RANGE, | ||
MATH_RANDI_RANGE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're up for one last refactoring, it would be good to use the opportunity to change the order here:
MATH_RANDI
MATH_RANDF
MATH_RANDI_RANGE
MATH_RANDF_RANGE
(i.e. int first, then float for the ranged version too)
And then adapt the order in all places where these enums are used to keep the same order as the enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or the other way around (float, then int) if we want alphabetical order instead:
MATH_RANDF
MATH_RANDI
MATH_RANDF_RANGE
MATH_RANDI_RANGE
@akien-mga I could make a randi_range exclusive, the advantage of inclusiveness - it's a more intuitive for raw usage, the disadvantage: things like arrays indexes or enums need to be cast down by 1 like |
Yeah I'm not sure what's best myself, exclusive would be like |
@akien-mga Also, I think the description of randf is incorrect - it actually exclusive and not inclusive - it generates value from 0.0 to 0.999999 (but never hits 1.0). |
That's probably due to the conversion from But yeah, I don't think a range in floating point can ever be expected to be inclusive anyway. |
Thanks! |
I see a lot of user help requests in Discord which has troubles with
randi_range
usage. Currently, it required to create an instance ofRandomNumberGenerator
, which may be uncomfortable for simple use cases. So I've addedrandi_range
to GDScript global functions, and renamedrand_range
torandf_range
(for logic compatibility with other functions + @akien-mga asked me to do that a while ago).The last change will probably break a lot of user scripts, so it's all up for @reduz and other core contributors decision