godotengine / godotengine/godot-docs
Your First 2D game: Creating the Enemy - randomize mod suggestion?
- Dominant language
- reStructuredText
- Stars
- 5.7k
- Forks
- 3.8k
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 25
Description
**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](https://docs.godotengine.org/en/stable/classes/class_array.html) 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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.