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

Implement Function: Array.pick_random() #57007

Closed
wants to merge 222 commits into from

Conversation

nonunknown
Copy link
Contributor

@nonunknown nonunknown commented Jan 20, 2022

Implements: godotengine/godot-proposals#3454

This is partially implemented, since some users suggested adding for another classes, but I think each class should have their own PR, what you guys think?

IMPORTANT:
First merge #54940 before this one, to avoid #54939

test code:

var arr:Array = []

func _ready() -> void:
	arr.append_array(["test",1,2,3])
	print(arr)
	for i in range(10):
		print("Result: ", arr.pick_random())

output:

First Run:

[test, 1, 2, 3]
Result: 2
Result: 1
Result: 3
Result: 1
Result: 3
Result: 3
Result: 2
Result: 1
Result: 1
Result: 1

Second Run:

[test, 1, 2, 3]
Result: 1
Result: test
Result: 2
Result: 2
Result: 1
Result: 1
Result: 2
Result: 3
Result: 3
Result: 2

@sairam4123
Copy link

Would be interested in adding in probabilities too?
Like this?
[1, 0, 2, 3].pick_random([0.25, 0.25, 0.25, 0.25])
It's your choice to to decide whether the sum of all probabilities must be 1. It's how it works in Python.

@nonunknown
Copy link
Contributor Author

Would be interested in adding in probabilities too? Like this? [1, 0, 2, 3].pick_random([0.25, 0.25, 0.25, 0.25]) It's your choice to to decide whether the sum of all probabilities must be 1. It's how it works in Python.

please create a proposal for that, every implementation depends on the users needs.

@Xrayez
Copy link
Contributor

Xrayez commented Feb 16, 2022

Would be interested in adding in probabilities too?

Recent proposal: godotengine/godot-proposals#3948

I do think having both methods is fine and even needed, though. Random.choice() exists in Goost btw, but if choices() is implemented as well, I've been thinking that choice() could be renamed to pick() (as seen in this PR):

Calinou and others added 2 commits April 16, 2022 13:10
- Display the source file path.
- Display the valid compression algorithms on desktop platforms.
- Use "desktop platforms" instead of "PC" to avoid ambiguity.
- Use "may" instead of "will", as desktop platforms can still sometimes
  display ETC1/ETC2 textures depending on the GPU and drivers.
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved in proposals review meeting.

@akien-mga
Copy link
Member

You need to update the class reference with --doctool and write documentation for the new method: https://docs.godotengine.org/en/latest/community/contributing/updating_the_class_reference.html

Apparently there's also a style issue but not sure which, you should likely run clang-format.

Calinou and others added 2 commits June 30, 2022 23:12
This allows not accounting for certain visible meshes during baking
(such as foliage and thin fixtures).

This also adds a clarification about transparent materials always
being excluded in the OccluderInstance3D documentation.
akien-mga and others added 24 commits August 9, 2022 22:55
[doc] Use "param" instead of "code"  to refer to parameters
There was no mention of the effect of AudioListener2D in this documentation, making it unclear if there was a relationship. The new text is copied and modified from the AudioStreamPlayer3D documentation.

Use 'an' as article before 'AudioListener3D'
…ly-one

Remove duplicate data structure for editor export features
@mhilbrunner
Copy link
Member

Seems this includes a lot of other commits :) Needs a proper rebase.

@akien-mga
Copy link
Member

akien-mga commented Aug 25, 2022

@nonunknown has been struggling with rebasing on this one. Maybe a contributor can help salvage this?

Closing for now as this is likely best redone from a clean master checkout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.