Skip to main content

Demo: Connection and Chat History

In the Project Panel, click Inworld > Inworld.Samples.RPM > Scenes > SampleConnection to open the demo about how to connect to Inworld sessions, as well as how to save and load game histories.

We provide a step-by-step guide on using specific code lines through three main sections: starting a new game, saving a game, and loading a game.

1. New Game

By default, the AutoStart setting in the InworldController is turned on.

This means that whenever a user begins the game, we automatically access the Inworld server to fetch the characters for the current scene and establish a connection.

However, in this demo, AutoStart is turned off. This means users need to manually click on "New Game" or the "Play" button at the top to make a connection.

AutoStart

Once a connection is made, the connection status with the Inworld server will be displayed in the upper left corner, and if the connection is successful, the ping latency will be shown every 0.1 seconds.

We also offer functionalities to mute/unmute and to turn the microphone on and off.

⚠️ Note: Acquiring ping is not available in a WebGL application.

NewGame

2. Save Game

In this demo, we demonstrate how to use the Save Game and Load Game features to manage game records.

For instance, if you tell a character in the game to Remember my favorite fruit is a banana and then click Save game, the Inworld Server will return an encrypted index of the chat history.

SaveGame

This Save button actually calls this following API to save the chat history of the current scene:

InworldController.Client.GetHistoryAsync(InworldController.Instance.CurrentScene);

This API triggers an asynchronous request to the Inworld Server for the chat history of the current scene.

The server then returns an encrypted index of the chat history, which contains all interactions with the character.

Developers need to save this index in an appropriate place for future reloading of these interactions.

3. Load Game

When you click Load Game, loading the previously saved encrypted string allows the character to recall the earlier conversation.

LoadGame

When it's time to load a previously saved game, the LoadScene method is employed not only to specify the scene to be loaded but also to input the previously saved chat history index (i.e., history). This allows the character to "recall" past interactions based on the saved history, maintaining the continuity of the game state. The method is called as follows:

public void LoadScene(string sceneFullName = "", string history = "")

The sceneFullName parameter allows for the specification of the full name of the scene if there's a need to start the game from a specific point; the history parameter is the previously saved encrypted chat history index. With this index, the game can reproduce the player's earlier interactions with the Inworld character.

This approach ensures that even after exiting and re-entering the game, players can seamlessly continue from where they left off, maintaining consistency in interaction history and context with the game characters.

⚠️ Note: Even though we provide the functionality to save chat histories, whether characters will "remember" this information and use it in subsequent interactions depends on the context and their designed personality. For data security reasons, chat records are not permanently saved by the Inworld Server. Thus, developers are responsible for ensuring the secure storage and handling of these data.