GDQuest / GDQuest/learn-gdscript

Suggestion: Clarify dictionary access with square brackets

Open
#1,360 0 comments 0 reactions 0 assignees View on GitHub
content
Dominant language
GDScript
Stars
2.8k
Forks
235
PR merge metrics
No merged PRs in 30d

Description

A student was confused by this line in L25

```gdscript
var item_count = inventory[item_name]
```

They expected the square brackets to "return" the dictionary key's position in the list of keys, sort of similarly to how you access values in an array by index. The lesson and perhaps previous lessons don't make the distinction between array indexes and dictionary keys explicit enough.

The Lesson 25 practice also did not clearly explain how this modifies the inventory:

```gdscript
inventory[item_name] += amount
```

Things we could improve:

- Review lessons probably 24 and 25 to clarify that `[]` is an access operator and it works differently depending on the context.
- Explain that arrays use an int index, while dictionaries use a key to look up a value. We should probably say that dictionaries themselves do not have positional indexes (NB: unless you call a function to get an array of keys or values, but that's not the dictionary anymore).
- Make sure we clearly explain and show that, in a loop over a dict, the loop variable contains one key at a time, and that using the brackets finds the value associated with that key. A visualization would help there and also mini exercises embedded in the lesson.

Related: #1217

Contributor guide

No contributing guide indexed for this repository

Research direction

Review Lessons 24 and 25, including the Lesson 25 practice, and inspect the examples using inventory[item_name] and inventory[item_name] += amount. Clarify array indexes versus dictionary keys, explain dictionary lookup in loops and updates, and add the proposed visualization or mini exercises where appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
godot
Domain
content, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.