SaveProfile

Data that lasts across saves and new games - settings, unlocks, endings found, high scores - as named values in one registry key. Every change is written straight away.

Properties

  • section (string)
  • key (string)
  • enabled (boolean) — While false, changes aren't written (reads still work from what's loaded).

Example

CODE
profile = new BGE.SaveProfile("my-game")
if profile.recordHighScore("arcade", score)
' a new best
end if

Constructor

new SaveProfile(section: string, key?: string): SaveProfile

Parameters

  • section (string) — registry section, e.g. your game's id
  • key (string, optional, default: "\"profile\"")

Instance Methods

reload(): void

Reads the profile from the registry again.

Returns

  • void

get(name: string, defaultValue?: dynamic): dynamic

Parameters

  • name (string)
  • defaultValue (dynamic, optional, default: "invalid")

Returns

  • dynamic — the value, or defaultValue if it isn't set

set(name: string, value: dynamic): boolean

Sets a value and saves.

Parameters

  • name (string)
  • value (dynamic) — anything FormatJson() can write

Returns

  • boolean — false if it couldn't be saved (see BGE.registryWrite()) or the profile is disabled; the value is still set in memory

has(name: string): boolean

Parameters

  • name (string)

Returns

  • boolean

remove(name: string): void

Removes a value and saves.

Parameters

  • name (string)

Returns

  • void

clear(): void

Removes everything, including the registry key.

Returns

  • void

getAll(): roAssociativeArray

Every value, by name. Don't change it - use set().

Returns

  • roAssociativeArray

addToSet(name: string, id: string): boolean

Adds id to a set kept under name (e.g. endings found).

Parameters

  • name (string)
  • id (string)

Returns

  • boolean — true if it wasn't there before

setCount(name: string): integer

How many ids are in the set kept under name.

Parameters

  • name (string)

Returns

  • integer

getHighScore(table?: string): integer

The best score recorded for a table, 0 if none.

Parameters

  • table (string, optional, default: "\"highScore\"")

Returns

  • integer

recordHighScore(table: string, score: integer): boolean

Keeps score if it beats the best for the table.

Parameters

  • table (string)
  • score (integer)

Returns

  • boolean — true if it's a new best