score.lua

do I need to physically create the scorefile.txt file?

I notice in the beginning of the score.lua code for each item eg. font etc. it has a “custom” variable. how are these used?

If you’re using the score.lua file from the tutorial that we did a few months ago, it should create the save file on it’s own.  However, if you’re using something else, we have no way of supporting this.

Where did you get this score.lua?

Rob

yes it’s the one from the tutorial. how does it create the file? and how do the custom variables work?

You don’t create the file yourself, you call score.save() and it will create the file, save the score to it.

The “custom” variables are simply things you pass when you create the score object.  In the tutorial, scroll down to the “Putting it to use” section.  It shows the score object creator passing in the various values that it will use.

Rob

regarding the custom variables, I just wasn’t reading the code properly… I get it now…

have another question though… I noticed in the comments you make reference to the following and I have seen others write it the same way:
[lua]
local highscore = score.load
highscoretext.text = highscore
[/lua]
this is a general code question but couldn’t you just write:
[lua]
highscoretext.text = score.load
[/lua]

highscoretext.text = score.load()

will work.  Function calls are a little more expensive than just assigning a variable.  If you are only going to use it here and no where else, what you did is perfectly legal.   But if you’re going to work with that value else where, its more efficient to have it in a variable.

Rob

cheers! where does scorefile.txt get created? I have it working but can’t see the file in the main folder. only change I did was to set score to 0 and return it if the file doesn’t exist under the load function.

Your folder with your main.lua is what’s known as system.ResourceDirectory.  Once your app is live, this is a read only folder.  The other folders like system.DocuemntsDirectory, etc. are stored on device somewhere  where the actual location is irrelevant.  You just use our constants:  system.DocumentsDirectory, system.CachesDirectory, system.TemporaryDirectory.

Now for the Simulator, you can do a File->Show Project Sandbox to open the folder on your hard drive where these three folders exist.  The scorefile.txt file is written to the system.DocumentsDirectory.

Rob

If you’re using the score.lua file from the tutorial that we did a few months ago, it should create the save file on it’s own.  However, if you’re using something else, we have no way of supporting this.

Where did you get this score.lua?

Rob

yes it’s the one from the tutorial. how does it create the file? and how do the custom variables work?

You don’t create the file yourself, you call score.save() and it will create the file, save the score to it.

The “custom” variables are simply things you pass when you create the score object.  In the tutorial, scroll down to the “Putting it to use” section.  It shows the score object creator passing in the various values that it will use.

Rob

regarding the custom variables, I just wasn’t reading the code properly… I get it now…

have another question though… I noticed in the comments you make reference to the following and I have seen others write it the same way:
[lua]
local highscore = score.load
highscoretext.text = highscore
[/lua]
this is a general code question but couldn’t you just write:
[lua]
highscoretext.text = score.load
[/lua]

highscoretext.text = score.load()

will work.  Function calls are a little more expensive than just assigning a variable.  If you are only going to use it here and no where else, what you did is perfectly legal.   But if you’re going to work with that value else where, its more efficient to have it in a variable.

Rob

cheers! where does scorefile.txt get created? I have it working but can’t see the file in the main folder. only change I did was to set score to 0 and return it if the file doesn’t exist under the load function.

Your folder with your main.lua is what’s known as system.ResourceDirectory.  Once your app is live, this is a read only folder.  The other folders like system.DocuemntsDirectory, etc. are stored on device somewhere  where the actual location is irrelevant.  You just use our constants:  system.DocumentsDirectory, system.CachesDirectory, system.TemporaryDirectory.

Now for the Simulator, you can do a File->Show Project Sandbox to open the folder on your hard drive where these three folders exist.  The scorefile.txt file is written to the system.DocumentsDirectory.

Rob