Storage.setItem method

  • setItem is a function that stores data in the GameSnacks storage system.

  • It takes a key (string) and value (string) as input, updating or creating a key-value pair.

  • The provided example demonstrates storing a user's earned stars using setItem.

setItem(
  key: string,
  value: string
): void;

Sets the value of the pair identified by key to value, creating a new key-value pair if none existed for key previously.

Examples

// User earns a new star.
starsEarned++;

GameSnacks.storage.setItem('starsEarned', starsEarned.toString());