Let’s say that I want to remember what the player has clicked on between sessions. How would you go about saving that data? I would probably do something with player preferences with Unity, but is there a equivalent with needle?
Hello there – we have an experimental AI bot that might be able to help you with your question. Would you like to try this out?
How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.
In Needle Engine, to save data between sessions similar to how you would use PlayerPrefs in Unity, you can utilize the localStorage web API directly in your TypeScript code. The localStorage object allows you to save key/value pairs in a web browser and persists even when the browser is closed and reopened.
Here is an example of saving and loading data using localStorage:
// To save data:
localStorage.setItem('myDataKey', JSON.stringify(dataToSave));
// To load data:
const loadedData = JSON.parse(localStorage.getItem('myDataKey') || 'defaultValue');
Remember that localStorage only supports strings, so you need to serialize your data to a string when saving (e.g., using JSON.stringify) and deserialize it back to its original form when loading (e.g., using JSON.parse).
If you plan to save objects or arrays, you need to serialize them into a JSON string before storing them and deserialize them back into objects or arrays when you retrieve them.
1 messages leftGPT 4 thread_dNO6QVPhuXdt0jXaNt3AJrev Thanks for your feedback!