We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Small Basic AI Championship
(translated by Google translator)

For the first time in the last 6 days, I have the opportunity to have fun with coding in Small BASIC.  Rolleyes
And today I used the "LDFile.SaveAllVariables" method for the first time.
So that I don't waste time on tests, please tell me whether this method saves lists of values?
( I am already sure that this method saves the values of simple variables. )

Thank you.
Reply
LDFile.SaveAllVariables saves all variables to a text readable file.  All SB variables are of type Primitive and can be converted to a string, including arrays.

It does not save the contents of variables in within standard SB or extension structures, for example it saves the label name for an image, not the actual image.  To be sure what it is saving or not, just look in the file.
Reply
Yes, now there really is a lot of text in that file.
However, when I looked at such a file during my first attempt at using the method, there was only one line with C# syntax.
I thought that this was how it should be and did not look at this file again.  Huh
Now I see errors when loading values from such a file. But I can tell you the details only tomorrow.
Reply
Of course, I couldn’t sleep because I really wanted to find the reason for the incorrect loading of the saved data.
Here's what I discovered.

In the file, the name of a variable and the value of that variable are separated by a space.
When I wrote code, I sometimes put several spaces in a row between the variable name and the "=" sign to make the text easier to read.
Therefore, when saving data to a file, the method writes additional spaces, the "=" sign, and all characters up to the end of the line as VALUE.
I see this in the Client window when displaying controlled parameters.

In addition, the VALUES of the lists are not saved. Only list names that are assigned to variables are saved.
If it's hard to fix, please tell me. Then I'll go the other way.

Thank you very much.  Shy
Reply
AB,

It won't save data stored in methods or extensions, for example LDList.

Can you create a small example code that doesn't work.

This is my test case:

Code:
a = 1
b = Math.Pi
c = "Hello world"
d[1] = a
d[2] = b
e[c][1] = 25
f[b][c] = "Something else"

path = File.GetSettingsFilePath()
LDFile.SaveAllVariables(path)

a = ""
b = ""
c = ""
d = ""
e = ""
f = ""

LDFile.LoadAllVariables(path)
TextWindow.WriteLine(a)
TextWindow.WriteLine(b)
TextWindow.WriteLine(c)
TextWindow.WriteLine(d[1])
TextWindow.WriteLine(d[2])
TextWindow.WriteLine(e[c][1])
TextWindow.WriteLine(f[b][c])
Reply
LitDev
Yes, sure. I will do this at the first opportunity.
Reply
(translated by Google translator)

Here's what I found in the saved variables file.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
. (from File) . . . . . . . . . . . . . . . . . . . . (from Code)
number_of_sequences = 624 . . . . . Text.Append("number_of_sequences = ", number_of_sequences)
number_of_dead_snakes = 2 . . . . . Text.Append("number_of_dead_snakes = ", _stat_deadSnakes)
Level of training(%) = 101  . . . . . . . Text.Append("Level of training(%) = ", _x)
Ratio = 23. . . . . . . . . . . . . . . . . . . . Text.Append("Ratio = ", Math.Floor(_stat_caughtRabbits/_x))
lis_SequenceLevel[i] =  . . . . . . . . . . Text.Append("lis_SequenceLevel[i] = ", LDList.GetAt(lis_SequenceLevel, n_sequenceNumber))
number_of_sequences = = 624 . . . Text.Append("number_of_sequences = ", number_of_sequences)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The saved variables file contains lines in which the method saved the "Text.Append()" function ARGUMENTS as variables.
When reading the file, the "number_of_sequences" variable received an incorrect value. I was able to notice this because the strings "Level of training(%)", "Ratio" and "lis_SequenceLevel[i]" are not variables at all.

Am I correct in thinking that it is better to use the "LDList.Write()" method to save lists, and "LDSettings." to save variables?  Huh

Thank you.
Reply
AB,

As I said, SaveAllVariables only stores the values of variables in the SB program, not anything stored in a LDList for example.

LDSettings is different again, it stores some specific settings, not values in all variables.

I would need a small sample program that shows an issue with SaveAllVariables to look at.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
Yes, I understand.
And that's why I'm looking for alternative ways to save lists and the variables I need.
For example, I can save lists using "LDList.Write()". And I can use "LDSettings." to save those variables that I will need during the next launch (not all that are used in the program).
Well, since I'm an Absolute Beginner, I'm simply asking if these methods are really the best choice in this case. Or maybe I didn't notice something again.  Blush

I will definitely try to write a short code that can show the errors that I am currently seeing during the Rabbit AI tests. Nowadays, various everyday problems fall on me one after another. These problems seem so unimportant to me compared to the pleasure of programming. This annoys me, but “business is business.”
I have to do this.  Angel

Thank you.
[-] The following 1 user Likes AbsoluteBeginner's post:
  • litdev
Reply
I was lucky.  Smile
I managed to assemble the code from fragments of the original Rabbit AI code and this code reproduces for me all the strange results of the SaveAllVariables method work.
Code:
'
_s_allVariablesFilePath = Program.Directory + "\RabbitAll_variables.txt"

number_of_sequences   = 625
n_sequenceNumber    = 0
_s_dbText = " "
_stat_caughtRabbits = 0
_stat_deadSnakes    = 0
_x = 0

If LDFile.Exists(_s_allVariablesFilePath) = "True" Then
  LDFile.LoadAllVariables(_s_allVariablesFilePath)
  OnRabbitCaptured()
Else
  number_of_sequences   = 300
  n_sequenceNumber    = 30
  _s_dbText = "Test"
  _stat_caughtRabbits = 300
  _stat_deadSnakes    = 30
  _x = 300
  OnRabbitCaptured()
  LDFile.SaveAllVariables(_s_allVariablesFilePath)
EndIf

Sub OnRabbitCaptured
  _s_dbText = _s_dbText + Text.Append("number_of_sequences = ", number_of_sequences) + LDText.LF
  _s_dbText = Text.Append("number_of_caught_rabbits = ", _stat_caughtRabbits) + LDText.LF
  _s_dbText = _s_dbText + Text.Append("number_of_dead_snakes = ", _stat_deadSnakes) + LDText.LF
  _x = Math.Floor((626 - number_of_sequences)/614*100)
  _s_dbText = _s_dbText + Text.Append("Level of training(%) = ", _x) + LDText.LF
  _s_dbText = _s_dbText + Text.Append("Ratio = ", Math.Floor(_stat_caughtRabbits/1)) + LDText.LF
  _s_dbText = _s_dbText + Text.Append("number_of_sequences = ", number_of_sequences)
  DrawBndText()
EndSub

Sub DrawBndText
  GW.BrushColor = "White"
  GW.FillRectangle(0, 0, GW.Width, GW.Height)
  GW.BrushColor = "Black"
  GW.FontBold = "False"
  GW.DrawBoundText(5, 5, GW.Width - 10, _s_dbText)
EndSub
The contents of my file with saved variables also look surprising. If necessary, I can post here the text of the file with variables and small screenshots of the test program window.

Thank you.  Shy
[-] The following 1 user Likes AbsoluteBeginner's post:
  • z-s
Reply


Forum Jump:


Users browsing this thread: 13 Guest(s)