# LoadLevel, StartLevel Logic

### NextLevel Execution Logic:

The image below shows how the LevelManager FSM logic within the NextLevel( ) method manages all tasks required for switching levels.  This diagram represents one section of the logic on the [LevelManager Diagram](https://kdoore.gitbook.io/cs2335/cs2335_f20/mini-game_proj3/level-manager-in-class/level-manager-logic-diagram), [LevelManager FMS with SubStates](https://kdoore.gitbook.io/cs2335/cs2335_f20/mini-game_proj3/levelmanager-fsm#levelmanager-fsm-with-sub-states-for-level-2-level2)

As events cause NextLevel to be executed, within the NextLevel( ) method, the first code executed is that the variable:  curLevel is changed to the next corresponding state as shown in the NextLevel table in the image below.  Then  either a StartLevel( ) or LoadLevel( ) method is executed, depending on whether transitioning to Level1, or to Level2 or Level3.  The subsequent diagrams show the logic exectued within each of these methods. &#x20;

![](https://1604956922-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-M5ST1MndDETSmRyYBmh%2F-M5Sm8wVMGa6whpc_Ygn%2FScreen%20Shot%202020-04-21%20at%2012.26.22%20PM.png?alt=media\&token=68a42176-e3e8-4b45-9047-dd16de199749)

The LoadLevel( ) methods have logic to stop spawning, timer, and to hide the player.  Then the LoadLevel( ) method has logic to show the StartPanel and configure the StartButton's text , AddListener for the corresponding StartLevel( ) method.

![](https://1604956922-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-M5ST1MndDETSmRyYBmh%2F-M5SmCECOud_0qwXp50x%2FScreen%20Shot%202020-04-21%20at%2012.26.37%20PM.png?alt=media\&token=b15d586a-081d-4ac8-9f1f-4ae03ffad7e5)

The StartLevel( ) method are exectued when the StartButton has been clicked.  It has logic for hiding the StartPanel and gameObjectLayers for the previous level.  The StartLevel( ) method has logic for showing current level gameObjectLayers, resetting the player's position back to the spawnPoint, and setting the player to be active.  It also sets the LevelText to display the currentLevel.  Finally, the StartLevel( ) method starts the Spawner for the currentLevel, and starts the timer.

![](https://1604956922-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-M5ST1MndDETSmRyYBmh%2F-M5SmG08B2QazSlYWpdi%2FScreen%20Shot%202020-04-21%20at%2012.26.45%20PM.png?alt=media\&token=b9190e6c-3447-4448-87bc-f21812e3e57b)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kdoore.gitbook.io/cs2335/cs2335_f20/mini-game_proj3/level-manager-in-class/loadlevel-startlevel-logic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
