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

Your First 2D game: Creating the Enemy - randomize mod suggestion? #9367

Open
robingamedev opened this issue May 12, 2024 · 0 comments
Open
Labels
area:getting started Issues and PRs related to the Getting Started section of the documentation enhancement

Comments

@robingamedev
Copy link

Your Godot version:
4.2.2

Issue description:

Currently, the tutorial shares this snippet:

func _ready():
	var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names()
	$AnimatedSprite2D.play(mob_types[randi() % mob_types.size()])

Thoughts on this?

func _ready():
	var mob_types = $AnimatedSprite2D.sprite_frames.get_animation_names()
	$AnimatedSprite2D.play(Array(mob_types).pick_random())

The pick_random() method is relatively straightforward to understand, and discussing the Array data type and its methods can be quite valuable for learning purposes.

Via https://docs.godotengine.org/en/4.0/classes/class_array.html#class-array-method-pick-random

URL to the documentation page (if already existing):
https://docs.godotengine.org/en/stable/getting_started/first_2d_game/04.creating_the_enemy.html

@Piralein Piralein added the area:getting started Issues and PRs related to the Getting Started section of the documentation label May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:getting started Issues and PRs related to the Getting Started section of the documentation enhancement
Projects
None yet
Development

No branches or pull requests

2 participants