How do I add modes to play based on other shots and not just ball/game start.
(a/k/a when to use
AdvancedMode.Manual).
1) Make sure the mode_type is AdvancedMode.Manual as shown below:
1 |
self.my_mode = MyCustomMode(game=self, priority=10,mode_type=AdvancedMode.Manual) |
2) Be sure to remember the name of the variable/reference that
holds the mode as defined in
T2Game.py.
In the example above, this is
self.my_mode so the Game instance
has a field called
my_mode; we can refer to it in Mode code via:
self.game.my_mode
3) In Mode code, you can refer to the
list of currently active modes (which lives in the game) as:
self.game.modes
So, to activate/start your new mode (
MyCustomMode) based on a specific
switch or event in a different mode, in that switch/event handler you would add:
1 |
self.game.modes.add(self.game.my_mode) |
3) To conclude that mode from:
3a) a different mode:
1 |
self.game.modes.remove(self.game.my_mode) |
3b) Within MyCustomMode itself:
1 |
self.game.modes.remove(self) |