updates to week 5 and 6 documentation

This commit is contained in:
OddlyTimbot committed 2025-05-26 16:46:51 -04:00
1 parent 8a23abe2ea
commit 6df4178596
2 files changed
+125 -13

No files matched your search

+14
View File
@@ -17,6 +17,20 @@ When we have reassigned the game controller to an autoload, it can be accessed b
Likewise the game controller should not directly reference any other class in the display list, since it is not longer a member of the display list. Instead, it should send out a signal that members of the display list can subscribe to.
## Autoload Singletons
The scene system in Godot is great for building multiple levels of a game and being able to run each one of them individually during development. However it does have a limitation.
When a scene is reloaded, or another scene is loaded in its place, all information is lost. This can be problematic for gameplay, because it means that variables storing information such as player health, number of enemies, etc. are lost when the scene is reloaded.
One answer to this is the use of an Autoload resource.
An autoload resource is one that can be specified in the project settings. It will be loaded ahead of all other resources, and can be given a name that can be referenced throughout the game by any other code. Data in this autoloaded resource will persist across scene changes.
An autoload script is a good place to put any persistent game logic and data, as well as any helper methods that may be useful to a wide variety of nodes in your game.
It is possible that an autoload script can get quite cluttered with information, so a good combination is to use an autoload script and data objects together.
### Example - Updating timer
Now that the game controller is persistent, it does not reload when the level timer completes. As a result, the level loads over and over again because it thinks the time has run out.