godotengine / godotengine/godot-docs

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

Open
#9,367 0 comments 1 reaction 0 assignees View on GitHub
area:getting started enhancement
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.