Skip to content
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

Automatically call randomize() in GDScript upon running a project #1774

Closed
Xrayez opened this issue Nov 4, 2020 · 4 comments · Fixed by godotengine/godot#43330
Closed

Automatically call randomize() in GDScript upon running a project #1774

Xrayez opened this issue Nov 4, 2020 · 4 comments · Fixed by godotengine/godot#43330
Milestone

Comments

@Xrayez
Copy link
Contributor

Xrayez commented Nov 4, 2020

Describe the project you are working on:
Godot Engine.

Describe the problem or limitation you are having in your project:
I don't, but users do:

I can likely find a bunch of other examples.

I recall stumbling upon the same limitation when I first started using the engine (like 4 years ago), with mostly lack of programming experience. So, I think this is mostly confusing to beginners.

See also #1590:

The global RNG has to be randomized implicitly, as in many other scripting programming languages.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
Call randomize() in the engine automatically for global RNG, so this is mostly about GDScript and built-in Math::random() usages in the engine. This should not affect local instances of RandomNumberGenerator classes.

Tests in C++ should use RandomNumberGenerator locally instantiated for reproducible random results (for stress tests), and of course in GDScript for similar use cases if you do need to control the seed, like procedural generation.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
It's a matter of calling randomize() somewhere in the engine. This breaks compatibility, but it's the perfect time for Godot 4.0.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
Sure, just call randomize() in GDScript.

Is there a reason why this should be core and not an add-on in the asset library?:
Already part of core.

@LikeLakers2
Copy link

I know this is done for the purposes of debugging games -- it makes it easier to replicate results.

That said, I wouldn't be against this being a Project Setting. It seems like a fairly reasonable setting to add.

@Xrayez
Copy link
Contributor Author

Xrayez commented Nov 4, 2020

That said, I wouldn't be against this being a Project Setting.

I agree because the RNG in Godot is not the only one out there, and other implementations can reuse the same project setting (in plugins and modules). But I know for sure that Godot is allergic to adding potentially "specific" settings, so I'd be personally happy with any decision. But one also have to take into account the amount of confusion this currently creates for beginners. 🙂

The new setting could be added in application/run/randomize_rng or something like that. And obviously, I propose to have it enabled by default.

@Xrayez Xrayez changed the title Call randomize() implicitly for true randomness in GDScript Automatically call randomize() for true randomness in GDScript Nov 4, 2020
@Xrayez Xrayez changed the title Automatically call randomize() for true randomness in GDScript Automatically call randomize() for true randomness in GDScript upon running a project Nov 4, 2020
@Calinou Calinou added this to the 4.0 milestone Nov 4, 2020
@Calinou
Copy link
Member

Calinou commented Nov 4, 2020

I think we should always do this. There's no need to add a project setting. For people who need determinism, they can create their own RandomNumberGenerator instance and set the seed manually.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 4, 2020

You don't even need RandomNumberGenerator, just call seed() when you need determinism.

@Xrayez Xrayez changed the title Automatically call randomize() for true randomness in GDScript upon running a project Automatically call randomize() in GDScript upon running a project Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants