Recently, a lot of csl users have been asking questions about the saving/loading features. So, we have decided to do an official writeup on the topic.

To get started, load the library into your code. (You can find it here)

require "crawlspaceLib"

For this demo, we are going to keep track of “points” using the data features of the crawl space library. Csl has a fuction called Defaults that sets everything up for us. We just need to pass in a table.

Defaults ( {

   points = 0

} )

On the first run, that code will set up everything we need to use saving and loading functionality. Now we need to load any existing data.

Load()

After that, we can use setVar() and getVar() to read and update the default data.

setVar( {'points', 100} )

Save()

That will increment “points” by 100 every time it is run. You can verify this by printing out the variable.

print(getVar('points'))

That is all there is to it. The crawl space library makes saving and loading data a breeze. Here is the code all together:

require "crawlspaceLib"

Defaults ( {

  points = 0

} )

Load()

setVar( {'points', 100} )

Save()

print(getVar('points'))

Let’s look at a more practical example. Here is a high score system made with csl:

require "crawlspaceLib"

Defaults ( {

  points = 0,

  highScore = 0

} )

Load()

local gameStart = function()

  setVar( {'points', 0, true} )

end

local addPoints = function(points)

  setVar( {'points', points} )

end

local gameOver = function()

  local score = getVar('points')

  if score > getVar('highScore') then

    setVar( {'highScore', score, true} )

  end

end

-- sample gameplay

gameStart()

for i=1, math.random(1,10) do

  addPoints(100)

end

gameOver()

--

print("Points: "..getVar('points'))

print("High Score: "..getVar('highScore'))

Save()

Breaking this into pieces, first we set up the defaults and load existing data.

require "crawlspaceLib"

Defaults ( {

  points = 0,

  highScore = 0

} )

Load()

Next we make a few functions to help us out:

We are going to track our current points with csl. addPoints() simply uses setVar() to add to the “points” value.

local addPoints = function(points)

  setVar( {'points', points} )

end

We also need to be able to reset the points at the start of each game. The gameStart() function uses csl to set “points” back to 0. Now normally, setVar() will increment itself if it can. In this case, we need to pass true as a third parameter. This parameter tells setVar() to set the variable instead of adding to it.

local gameStart = function()

  setVar( {'points', 0, true} )

end

To wrap up the game, we should check if the current “points” are greater than “highScore”. If they are, we need to update with the new high score.

local gameOver = function()

  local score = getVar('points')

  if score > getVar('highScore') then

    setVar( {'highScore', score, true} )

  end

end

Next we have a simple loop that demonstrates what a game might look like:

gameStart()

  for i=1, math.random(1,10) do

addPoints(100)

end

gameOver()

First we reset “points”. Next we randomly add to “points”. Finally, If there is new high score, we set it.

Now we can wrap it all up by saving our data and printing it out.

print("Points: "..getVar('points'))

print("High Score: "..getVar('highScore'))

Save()

Hopefully this gives a pretty clear picture of the power and ease of the data functions in the Crawl Space Library. This is just scratching the surface of what csl can be used for. There are even more features in the Save/Load functions, such as saving any table and saving to a non-default file:

local levels = {1,2,3,4}

local filename = "levels.txt"

Save(levels,filename)

There you have it, an easy way to store data using the Crawl Space Library. There are tons of uses for these features, and I am looking forward to seeing what you come up with. Go checkout csl if you haven’t already. It has a lot of cool stuff and more just around the corner. Again, you can find that here. Feel free to drop us a comment below and share what you have been using the library for.

Enjoy! –Lance

We recently had a painful experience and wanted to share it with the game dev community so you can learn from it and not make the same mistake we did. Do you ever have problems keeping track of your keys? I’m constantly misplacing my keys and asking my wife if she has seen them. If you’re an app developer you have a set of virtual keys that are just as important as your physical keys and those keys are your keystore files for Android and provisioning profiles for iOS. I don’t know how much you know about the differences in the signing processes between iOS and Android, but they are quite a bit different. Apple holds your hand and helps you manage those provisioning profiles in the developer area of their site. Android, on the other hand, completely turns you loose and gives you full control of managing your own keystores. Its a kin to two different parenting styles, where the Apple dad knows that their children are going to mess up sometimes and believes its good to have a safety net, so they don’t completely screw up their lives. While the Android dad believes that kids should live their lives and learn from their mistakes and nudges them out of the nest to fly on their own. You can argue the merits of each approach, but they are different and those little magic files you sign your apps with are different as well. If you misplace your iOS provisioning profile, papa Jobs has a spare copy for you to download. If you misplace your keystore, in the words of Walter from Big Lebowski…”You’re entering a world of pain”.

 

We entered that world of pain recently. Two of our computers died and the keystore for signing the Nook version of Float could not be found. We had all of the other files for that game in our repo, but for the life of us we could not find that keystore file. The kicker of the whole story is that we pushed an update to Float where we added more modes and signed it with a different keystore than the first time. We didn’t realize that we had signed with a different keystore and Barnes & Noble didn’t catch it either. When people when to update Float, they couldn’t get it to work. Not only couldn’t they get the update to work, but they could no longer play the old version either. Emails from 20,000 mothers informing me that their children could no longer play the game that they loved quickly started to pour in. …”A world of pain.” That isn’t a situation any app developer wants to be in. So we did some research to see if we could extract the keystore or recreate it in some way and needless to say—keystores are like beautiful unique snowflakes. There is absolutely no way to fake or recreate the keystores used to sign your apps and thats the point. Its a security measure and a very good one.

 

Long story short, after some back and forth with B&N, which I must say they were very helpful and they have an awesome team, we submitted Float HD. We had to submit a completely new app and allow it to be free for one week so all the people having problems could switch over to the new version and the old version of the app was removed from the store. The solution was kind of a bummer because Float was the second highest rated game just behind Angry Birds, but if you do some research on lost keystore you will find that our story is far better than some of the horror stories people have gone through. For example, one developer signed twenty of his paid apps with the same keystore and his laptop was stolen. He now has twenty apps that he can no longer update…ouch. Moral of the story? Hold on to your keystore file kids. Store them in a repo, email them to your self, send them to a friend, put them on a usb key and stash it in a safe. Whatever you do, just make sure you have it backed up somewhere.

 

Also, if you have a Nook go get Float HD, which is free for one week.

When I got up today the sun was shining, the birds were singing, the loud garbage truck was banging around outside, and I was inspired. Now, I don’t want to sound like a d-hyphen-bag motivational speaker, but I want to share some interesting bits of information that have encouraged me. I don’t know what types of games you are creating or for what platforms, but I make mobile games. So naturally I look to the games that have climbed their way to the top of the charts and have remained there. Doodle Jump and Angry Birds are two shining examples of success in my industry. Did you know that Doodle Jump was Lima Sky’s 12th game and Angry Birds was Rovio’s 52nd game? We’re working on our fifth game now, so we know we have a long way to go, but we remain hopeful. Keep your heads up indies. It doesn’t matter what game number you’re on or how your past games have done. Keep learning and improving your craft and you never know, that next game could be the one to catch fire and burn up the charts.

 

Socialize

Crawl Space

Stalk Stick

Games

Comics

Good Ol' Sites

Elevate Entertainment