PacktPublishing / Learning-GDScript-by-Developing-a-Game-with-Godot-4

Learning GDScript by Developing a Game with Godot 4, published by Packt
MIT License
17 stars 8 forks source link

P71 Square-bracket dict access does not return null #17

Open ibbathon opened 1 month ago

ibbathon commented 1 month ago
var item = {
    "name": "Boots",
    "price": 5,
    "weight": 3.9
}
print(item["height"])

This will result in an "Invalid access" error, triggering the debugger, not a simple null output. I think you meant to use item.get("height") but then didn't cover the .get method in chapter 3. Considering how useful .get is (especially the 2-arg version), it might make sense to include that in chapter 3 if you make a 2nd edition.