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

Open Beginner friendly
#9,367 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Stale

Research direction

Start with the tutorial page at getting_started/first_2d_game/04.creating_the_enemy.html and review the current enemy animation snippet. Update the example to use the proposed Array and pick_random() approach, including the suggested explanation of the relevant Array method. Done when the tutorial accurately presents the revised example and remains clear for learners.

Written by the indexing model from the issue text.

Description

area:getting started enhancement

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

Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
7d 14h
Merged PRs (30d)
41

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from godotengine/godot-docs

All issues in godotengine/godot-docs

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.