LiveGame
⚠️
This page is under construction.
LiveGame is the main class that represents the game's current state.
Public Properties
game
The Game instance
Public Methods
getStorable
newGame
Starts a new game
return this
deserialize
Load a saved game
After calling this method, the current game state will be lost, and the stage will trigger force reset
**Note: **Even if you change just a single line of script, the saved game might not be compatible with the new version
Example:
const savedGame = {
// ...saved game data
};
// use hook inside a component
const {game} = useGame();
// pass the saved game data to the game instance
game.getLiveGame().deserialize(savedGame);
savedGame: SavedGame
- SavedGame
serialize
Serialize the current game state
You can use this to save the game state to a file or a database
**Note: **Even if you change just a single line of script, the saved game might not be compatible with the new version
return: SavedGame
- See SavedGame`
onCharacterPrompt
Called when a character says something
fc: (event: LiveGameEvent["event:character.prompt"]) => void
- See LiveGameEvent- Returns
LiveGameEventToken
- See LiveGameEventToken
const {game} = useGame();
const [texts, setTexts] = useState<string[]>([]);
useEffect(() => {
const token = game.getLiveGame().onCharacterPrompt((event) => {
setTexts((prevTexts) => [...prevTexts, event.text]);
});
return () => {
token.cancel();
};
}, []);
return (
<div>
{/* Your Text Log */}
</div>
);
onMenuChoose
Called when a menu is completed
fc: (event: LiveGameEvent["event:menu.choose"]) => void
- See LiveGameEvent- Returns
LiveGameEventToken
- See LiveGameEventToken