2020-02-10 21:05:09

Hello! So, i have looked at the bgt-manual carefully. When i look both at the serialize and deserialize functions, they both look the same. I've followed the tutorial and have done exactly as it suggests, but still my data won't save after closing the game.

Let's say i've serialized and deserialized a dictionary, but how can i write the serialized/deserialized data to a file, then load the saved data back when i next time launch the game?
Sorry if the explanation sounded like a mess. I've provided an example situation here: I've set my cash at 10000. I do the serialize and deserialize things. How can i write those variables into a file so that the game recocnizes it and loads my data back, if i for example spend 2000 of my cash when i play the game, so i have 8000 cash left. When i next time launch the game, i have only 8000 cash, not 10000. How can i do that? The bgt manual doesn't cover it. Hope you understood, and please try to help me asap.

Best regards: Marco

2020-02-11 08:13:03

if the bgt manual didn't cover it, then how would any of us know?

2020-02-11 11:02:01

You're horrible guys.
@Marko, could you upload the BGT manual? My desire to help is not so masochistic that I will install BGT lol.

If you want to contact me, do not use the forum PM. I respond once a year or two, when I need to write a PM myself. I apologize for the inconvenience.
Telegram: Nuno69a
E-Mail: nuno69a (at) gmail (dot) com

2020-02-11 14:54:32

Seriously, you had to create multiple topics asking the same question?
To write a dictionary to a file you serialize it and then write the result.  To load you would use the inverse. That is, read, deserialize, and then get values.
No code will be provided, it is your job to look up the necessary functions.  I will tell you that you had most of what was required in your other topic with the same issue.

2020-02-11 15:52:48

@ Nuno i sent you a pm. Go check it.

Best regards: Marco

2020-02-11 19:40:44

Ok guys this is the last time for a long time i'm gonna ask question related to this in this forum. So, i believe i figured out how to save the data so that it loads back when the game launches. This is a completely new code, and i get this error. My code is also included. I tried to figure out what's wrong with my code but found nothing.
Code:

int cash=50000;
file test;
dictionary data;
tts_voice voice;
void main()
{
voice.speak_wait("you have"+cash);
while(true)
{
if(key_pressed(KEY_RIGHT))
{
cash=cash-20000;
}
}
save();
}
data.set("cash",cash);
test.open("data.txt", "wb");
test.write(data);
test.close();
bool load(string save)
{
if(data=="")
{
return false;
}
dictionary @data=deserialize(data);
reset();
data.get("cash",cash);
test.open("data.txt", "rb");
string data=test.read();
test.close();
}
Error:

File: C:\Users\marco\Documents\test.bgt
On line: 17 (5)
Line: data.set("cash",cash);
Error: Expected identifier

File: C:\Users\marco\Documents\test.bgt
On line: 17 (5)
Line: data.set("cash",cash);
Error: Instead found '.'

File: C:\Users\marco\Documents\test.bgt
On line: 18 (5)
Line: test.open("data.txt", "wb");
Error: Expected identifier

File: C:\Users\marco\Documents\test.bgt
On line: 18 (5)
Line: test.open("data.txt", "wb");
Error: Instead found '.'

File: C:\Users\marco\Documents\test.bgt
On line: 19 (5)
Line: test.write(data);
Error: Expected identifier

File: C:\Users\marco\Documents\test.bgt
On line: 19 (5)
Line: test.write(data);
Error: Instead found '.'

File: C:\Users\marco\Documents\test.bgt
On line: 20 (5)
Line: test.close();
Error: Expected identifier

File: C:\Users\marco\Documents\test.bgt
On line: 20 (5)
Line: test.close();
Error: Instead found '.'

Best regards: Marco

2020-02-11 20:55:58

Please go read your other topic in which I specifically give advice on how to find solutions to the errors you experience.
Other than that, your code looks correct for the most part. The only thing that I would remove is opening and closing file from your load function. That, or move it to the top, as you’re trying to read from the data that is not actually there if you pass in the file path to the function.

2020-02-12 20:09:57

Sorry guys, but whatever i try, whatever lines i remove, it just won't fix. I get more interesting errors. Here is my code:
int cash=50000;
file test;
tts_voice voice;
void main()
{
string data=test.read();

voice.speak_wait("you have"+cash);
cash=cash-20000;


dictionary reset;
test.write(reset);
dictionary @reset=deserialize(data);
reset.get("cash",cash);

}
And the error:
File: C:\Users\marco\Desktop\testi\test.bgt
On line: 4 (1)
Information: Compiling void main()

File: C:\Users\marco\Desktop\testi\test.bgt
On line: 13 (6)
Line: test.write(reset);
Error: No matching signatures to 'file::write(dictionary&)'

File: C:\Users\marco\Desktop\testi\test.bgt
On line: 13 (6)
Information: Candidates are:

File: C:\Users\marco\Desktop\testi\test.bgt
On line: 13 (6)
Information: double file::write(string&in) const

File: C:\Users\marco\Desktop\testi\test.bgt
On line: 14 (13)
Line: dictionary @reset=deserialize(data);
Error: 'reset' is already declared

This is so confusing, i think i did everything right...

Best regards: Marco

2020-02-13 04:34:09

First, what are you trying to do here?
You seem to try and read from a file which is closed.
Then you try and write a dictionary to it. Okay... but you must use serioilize() on it first.
Then you try to... uh, desiriolize the unseriolized data? This is the strange part. Please go reread the language tutorial. Try and build simple games with it first. Don't get in over your head. Your code right now shows to me that you are trying to slap things together without understanding why and how to use the tools at your disposal.

2020-02-13 09:31:34

also, and I know this means I'm officially a hippocrit, choose a different language if you aren't grasping bgt. I mean, in the time you've spent learning it, you seemed to have half-grasped a few things. try soething else if it's not working. like python, pure basic, I don't know. those would be the two coming into my head when I think beginner programmer.

2020-03-16 11:28:15

Hello all! I just wanted to let you know that i know how to do what i asked! A huge thanks to Oriol!

Best regards: Marco

2020-03-16 18:59:57

When sample of your work will be available?

meow meow.

2020-03-17 11:03:09

PatrykK wrote:

When sample of your work will be available?

I already know it works.

Best regards: Marco