Small Basic - GetSettingsFilePath
There are only 16 keywords and 20 objects in Small Basic, and I've been playing with Small Basic for a few years now and thought I was pretty familiar with them.
I discovered one I have never used before following a post by Pappa Lapub in this forum thread Need help figuring out a way of showing score in my game.
The command is File.GetSettingsFilePath() and is a useful way to get a file path for a settings file.
A settings file can be used to store data from one run of your program to the next. Here is Pappa Lapub's example:
settingsFile `` = ``File``.``GetSettingsFilePath``(``)
scoreInit `` = ``12345
tb `` = ``Controls``.``AddTextBox``(``10``,``10``)
Controls``.``SetTextBoxText``(``tb`` , ``scoreInit``)
save `` = ``Controls``.``AddButton``(``"Save Score"`` , ``200``,``10``)
load `` = ``Controls``.``AddButton``(``"Load Score"`` , ``200``,``40``)
Controls``.`` ButtonClicked `` = ``OnButtonClick
Sub ``OnButtonClick
`` lastButton `` = ``Controls``.``LastClickedButton
`` If ``(`` lastButton `` = `` save `` And ``Controls``.``GetTextBoxText``(``tb`` ) ``<`` > ``""`` ) ``Then
`` score `` = ``Controls``.``GetTextBoxText``(``tb``)
``File``.``WriteLine``(``settingsFile``,``1`` , ``score``) ``' Save score to file
``Controls``.``SetTextBoxText``(``tb`` , ``""``)
`` ElseIf ``(`` lastButton `` = ``load`` ) ``Then
`` score `` = ``File``.``ReadLine``(``settingsFile`` , ``1``) ``' Load score from file
``Controls``.``SetTextBoxText``(``tb`` , ``score``)
``EndIf
EndSub
The settings file name is based on the file name that you save your program with - so you have to save the example above somewhere first to use it with a settings file.
If you save your file as for example C:\Users\Public\Documents\SmallBasic\steve\SettingsFileExample.sb, then the settings file will be C:\Users\Public\Documents\SmallBasic\steve\SettingsFileExample.settings.
The 16 keywords are And, Else, ElseIf, EndFor, EndIf, EndSub, EndWhile, For, GoTo, If, Or, Step, Sub, Then, To and While.
The 20 objects are Array, Clock, Controls, Desktop, Dictionary, File, Flickr, GraphicsWindow, ImageList, Math, Mouse, Network, Program, Shapes, Sound, Stack, Text, TextWindow, Timer and Turtle.
Comments
- Anonymous
September 29, 2014
This is a great score solution from Pappa Lapub!