This repository was archived by the owner on Jan 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 120
api write save data
Jesse Freeman edited this page Nov 11, 2021
·
1 revision
The WriteSaveData() API allows you to write saved data by supplying a key and value. Once saved, this data persists even after restarting a game.
WriteSaveData( key, value )| Name | Value | Description |
|---|---|---|
| key | string | A string to use as the key for the data. |
| value | string | A string representing the data to be saved. |
In this example, we are going to attempt to read the last time the game was loaded. When the game shuts down, it will save a timestamp to be read the next time the game is run. Running this code will output the following:
![]()
function Init()
-- Example Title
DrawText("WriteSaveData()", 8, 8, DrawMode.TilemapCache, "large", 15)
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)
-- Draw the last opneded text
DrawText("Last Opened", 1, 4, DrawMode.Tile, "large", 15)
-- Draw the saved data to the display
DrawText(ReadSaveData("LastOpened", "Never"), 1, 5, DrawMode.Tile, "large", 14)
end
function Draw()
-- Redraw the display
RedrawDisplay()
end
-- When the game shuts down, it will automatically save the timestamp
function Shutdown()
-- Write timestamp to the saves.json file.
WriteSaveData("LastOpened", os.date('%Y-%m-%d %H:%M:%S', ts))
endusing System;
namespace PixelVision8.Player
{
class WriteSaveDataExample : GameChip
{
public override void Init()
{
// Example Title
DrawText("WriteSaveData()", 8, 8, DrawMode.TilemapCache, "large", 15);
DrawText("C Sharp Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
// Draw the last opened text
DrawText("Last Opened", 1, 4, DrawMode.Tile, "large", 15);
// Draw the saved data to the display
DrawText(ReadSaveData("LastOpened", "Never"), 1, 5, DrawMode.Tile, "large", 14);
}
public override void Draw()
{
// Redraw the display
RedrawDisplay();
}
// When the game shuts down, it will automatically save the timestamp
public override void Shutdown()
{
// Write timestamp to the saves.json file.
WriteSaveData("LastOpened", DateTime.Now.ToString());
// TODO need a utility to write this to the file system since it's not run in the main engine
}
}
}- Game Project
- Lua Games (coming soon)
- C# Sharp Games
- C# Sharp Vs Lua
- API Cheat Sheet
- Enums
- Visual Studio Code
- Atom
- Tiled (Coming Soon)
- Aseprite (Coming Soon)
- AddScript
- BackgroundColor
- Button
- CalculateDistance
- CalculateIndex
- CalculatePosition
- CharacterToPixelData
- Clamp
- Clear
- Color
- ColorsPerSprite
- Display
- DrawMetaSprite
- DrawPixels
- DrawRect
- DrawSprite
- DrawText
- DrawTilemap
- Flag
- InputString
- IsChannelPlaying
- Key
- LoadTilemap
- MaxSpriteCount
- MouseButton
- MousePosition
- NewCanvas
- NewPoint
- NewRect
- PaletteOffset
- PauseSong
- PlaySong
- PlaySound
- ReadAllMetadata
- ReadMetadata
- ReadSaveData
- RedrawDisplay
- Repeat
- ReplaceColor
- RewindSong
- ScrollPosition
- SongData
- Sound
- SplitLines
- SpriteSize
- Sprite
- StopSong
- StopSound
- Tile
- TilemapSize
- TotalColors
- TotalSprites
- UpdateTiles
- WordWrap
- WriteSaveData