Change some game parameters from other scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By undergroundhand

I’m currently doing a Pong game, and I think I got a pretty nice result, but I’m having two problems finalizing it:

  • I have a Main Menu scene, with some button options (1P that goes into easy/normal/hard ptions; and a multiplayer option). From this Main Menu scene, the game goes into the Game scene. But I don’t know how to change some parameters from some objects in the game, based on what I press on the previous scene (the main menu)
  • For example, the main state of the game is what I would consider the “easy” option for 1P. But if I click on the normal or hard option, I don’t know how to affect directly the speed of the ball and the speed of the AI on the code.
  • There’s a similar problem for the 2P option. The main state of the game is with a pretty basic AI, but if I click on the 2P option on the main menu scene, I don’t know how to alter the code of the enemy to change it to only a controllable sprite, without my AI code.
  • I know how to make a controllable sprite for the second player, or to speed up the ball on every collision, or increase the A.I speed, I just don’t know how to do this “exchange” of code based on what I press on the previous scene.

I could avoid all of these questions by having a new scene for all the options (1P/Easy, 1P/Normal, 1P/Hard, and Multiplayer), but I don’t think this is a wise choice for organization and optimization.


:bust_in_silhouette: Reply From: Inces

You need to have any script, that persists through menu scene and game scene. All persistent data should be kept in such a script.
You can create a game menager scene, that resides in highest scope, and has menu and actual game as children. Or You can create autoload script.