This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
Quick Initialization of Persistent Data #67
carsakiller
announced in
Dev Thoughts
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This tip is a pretty quick and easy one but I found it to be a nice little trick for initializing
g_savedata
values.In
onCreate()
, you will have to get the values that you have stored ing_savedata
, something like so:There is an issue with this, however. If this save is brand new, then
g_savedata.vehicles
isnil
. Instead, we would like to initialize it as an empty table. You could do the following:However, I find a much cleaner and more reliable option to be the following:
This means that
g_savedata.vehicles
will be equal to theg_savedata.vehicles
table if it is notnil
orfalse
and if it is, theng_savedata.vehicles
will be an empty table{}
. And that is how we initialize all of ourg_savedata
variables for Carsa's Commands. We also define some shorter names just to make our lives easier.Carsas-CommandsV2/src/script.lua
Lines 2959 to 2981 in 7039894
Beta Was this translation helpful? Give feedback.
All reactions