Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Save and load data problem

Author
Message
Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 17th Dec 2012 22:04
When I implemented the read and write commands into my program and then run it the program crashed at the point of saving the integers and strings saying windows explorer has stopped working. I had 3 integers and 2 strings writing to my txt file. When I run the program again everything worked fine, writing and reading but then when I added another 20 integers and 50 strings to the write part of the program the program crashed again at the writing point, only this time no matter how many times I run the program it crashes at the same point. Is there a limit to how many integers and strings you can get your program to read and write? Thanks for any help
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 17th Dec 2012 22:23
There are no limits to the file read/write.

It would help to see the code you are using for the reading and writing.

And what version of AppGameKit are you using?

And are you working in Tier 1 (AGK IDE) or Tier 2 (MS Visual Studio)?

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 17th Dec 2012 23:00
I'm using tier 1 basic and I'm using the same code as listed in the example program's . A=readinteger (1). Writeinteger (1,a) etc. I am still using the trial version of agk basic also, does that make a difference? .
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Dec 2012 03:44
It is not impossible that the file operations are limited in the trial version.

But, seeing your code might make it easier to see if there is some issue with how you are reading and writing. Not necessarily all of the code, but the code related to the writing and to whatever function you are using to handle it.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 18th Dec 2012 16:09
Ok I will post my code when I get on laptop later. How do I do this? I gather I have to copy n paste a section of my code to the screen but how do I hide it behind a link like people do so my post doesn't automatically fill up with my code
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Dec 2012 18:13
You use the 'code' buttons at the top of the Post Forum Message input to wrap your code in '
' tags so that it is closed until someone clicks on it and then it opens up.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 18th Dec 2012 19:47 Edited at: 18th Dec 2012 19:54



thats the writing part



and thats the reading
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 18th Dec 2012 20:14 Edited at: 18th Dec 2012 20:15
you may wanna look into using arrays or even types... and use a small loop! just for the sake of shortening the code!

Hail to the king, baby!
Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 18th Dec 2012 20:21
what i have noticed is that if i get my program to go through the read commands (as per 2nd code snippet above) first and then go through the write commands (as per 1st code snippet above) next then everything seems ok, its only when the program goes through the write commands first that it crashes with mygame.exe has stopped working. But i need both options to work as i want my program to have a new game option where as u start off from stratch set up your name etc and then write to file at various points of game, and then i want my program to have a load game option where u continue from the last point in your game by reading to file and then writing at various points
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Dec 2012 20:32
I don't see returns at the end of either of your segments.

Since you are using labels (_mainmenu: and _dove3 I am assuming that they are executed with gosub calls.

If you don't have a return at the end your stack could be getting corrupted and/or you aren't actually executing things in the order you expect them to be.

Also, definitely use arrays and loops instead of single variables for all of the things you are writing/reading. Maintaining the code you have posted is going to be a nightmare for you in the long run.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 18th Dec 2012 20:45
i use them labels as i have goto's. they are not as a gosub, although i have some gosubs elsewhere i also use return in them. My program all works fine, i have tested many many times its just this problem with writing!!!. Is it because i am not using arrays that my program is crashing ...although as ive just said the program all works fine when i run the program read first then write
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Dec 2012 20:47 Edited at: 18th Dec 2012 21:11
There's no end of file checking either. Not sure what AppGameKit does when you try to read past the end of a file, presumably a runtime error would occur.

Edit: we might need to see how you use your gotos. Gotos are notorious for creating spaghetti code and being very hard to debug which is why, in most circumstances, it's highly discouraged.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Dec 2012 21:30
I didn't say it wouldn't work. But it looked like you might be using gosub calls, so I was offering something that might be an issue.

Hodgey is right. It is hard to figure out what the problem is with just those two bits of code.

While the goto command exists, it does make spaghetti code a possibility and that can cause problems, especially when trying to debug. I've had a lot of experience dealing with code done with lots of goto calls (not mine, other peoples) and it is very hard to follow the flow.

If, by chance, you should happen to do a goto call into the middle of a subroutine block or use one to leave a subroutine block, you run the risk of really messing up the execution stack.

Not knowing the order of your gosub and goto calls, and where the read and write groups are occuring, it is hard to figure out where the issue is.

I've not heard of anyone having an issue reading/writing files. In my app it creates a new options file and the reads it. Since the player can change the options at any time, the file gets completely rewritten regularly. And I've not run into any issue.

In general, it is much safer to do things in functions instead of gosub structures (using globals or passing in variables).

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 18th Dec 2012 21:34



my gotos are just like that, going from one screen to the next with the odd gosub just to flash the sprite when clicked etc. Well it seems that my program works fine when i read first so what i may have to do is when i click on new game get the program to read as it would if i was loading the game but then reset all the integers and strings to how it should be when you start a new game and then write the integers and strings, that way the program always reads before it writes
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 18th Dec 2012 21:44
Do you have a blank file named dovey.txt in your media directory?

If so, just create one with the values you want for initial values for a fresh game and read it at the start.

When you write the file it is NOT going into the application's media directory, it is going into the appropriate sandbox location for the platform it is running on. In the case of Windows, it is in your Documents\AGK\<yourappname>\media directory.

Subsequent reads of the file will be from the sandboxed location and NOT from the application's media directory. Once a file of the same name is written to, your app will never read it from the original media directory.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Dec 2012 21:56 Edited at: 18th Dec 2012 21:57
What happens after all of the writing to the file? It might not necessarily be writing to the file that's the problem, but what happens afterwards.

At this stage, I highly recommend removing all gotos from your program and replacing them with gosubs or functions.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 18th Dec 2012 22:56
I agree with AL and Hodgey. Goto should be used only in extreme circumstances (like errors in recursive descent compilers). You have to be very certain of your stack state if you jump out of a function. Most modern compilers don't let you do that.

You can reduce the nightmare by using functions for newgame etc.

I think it's important to use if and else rather than just if blocks, because, for example, you say:

if x = 1 then x = 3
if x = 3 then WoW!!

you have changed something that you are testing in the same code sequence.

Better still to use case statements with numeric values. They are faster, and usually optimised by the compiler.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 19th Dec 2012 02:06
I would rewrite it.

That would save all the data into an array, and allow easy loading. You could also loop the data entry with some extra work, rather than adding it manually. It all depends on how much data you will be adding. With as much as you are using, I would consider splitting a string to get your data rather than using separate variables.

Doveyy04
12
Years of Service
User Offline
Joined: 30th Apr 2012
Location:
Posted: 19th Dec 2012 11:51
Thanks for the help guys, I will learn arrays and use them in my program. I don't think there is nothing going on after the writing to cause the problem happens before it gets to close file as the data hasnt been writing when i run the program again that I do know. My program does seem to work fine with all the gotos but then I havnt compiled it yet just run it in windows so maybe it won't work then. I don't have a dovey.txt file in my media file as I was looking for it and wondered why it wasn't in my project files so how do I create a txt file in my project media folder with the data I want for a fresh game?
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 19th Dec 2012 15:04
You would create it yourself. I used dovey as you used it in your example. The code I posted should create a text file called dovey.txt. I haven't put any data in though, it was just an example (Running it as is will save no data).

You will locate the file in your documents folder, under AppGameKit, then your project name. Inside the media folder in there, it should have generated a new txt file called dovey.txt. Until you add data though, it will be blank.

Login to post a reply

Server time is: 2024-11-24 03:42:54
Your offset time is: 2024-11-24 03:42:54