Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+2)

Declaring deck-level "shortcuts" to widgets and helper functions are definitely useful techniques!

For a simple key-value store, one alternative to using a grid widget is using the ".data" attribute of a field widget, which can directly represent numbers, strings, lists, or dictionaries, among other things.

Here are some equivalents to your grid-based helper functions:

on get x k do x.data[k] end
on set x k v do x.data:x.data[k]:v end

Used like so:

set[field1 "alpha" 5]
set[field1 "beta" 2]
get[field1 "alpha"]  # 5

For the specialized case of games that just need to keep track of a bunch of global boolean "game flags", you could make something like this:

flags:somecard.widgets.some_storage_field
on get   k do 0+flags.data[k] end
on set   k do flags.data:flags.data[k]:1 end
on clear k do flags.data:k drop flags.data end

Since these functions only take a single string argument, we can use an extra-concise syntax for calling them:

set["beta"]  # this works
set.alpha    # this also works!
get.alpha    # 1
clear.alpha
get.alpha    # 0

Thanks for helping share what you've learned, Missooni!

(+1)

I had no idea how to use the .data attribute of a field when writing this, so I'll get acquainted with that and remake this guide altogether. Thanks for the feedback.