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 / Programming bug or AGK bug?

Author
Message
badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 30th Dec 2011 03:25
I am working on creating a High Score server app where I can post my high scores on a server and allow players to see other global high scores. I know there is probably a better way, but if I can figure it out, then it opens up a bunch of other options in later game development.

I started with the code that was in the multiplayer guide. I was adding the ability for my app to read from a file and write to a file. This way, if the app stops unexpectedly, I can just run it again and it will read the last saved file and continue.

Here's what I have:



You should be able to drop in a new project locally and run to follow.

First, the code above does not run. I have to uncomment line 131. It deletes the file if it exists. This is problem #1. Shouldn't "OpenToWrite("HighScores.txt", 0) do that for me?

Second, I would like to use lines 136 - 138, but it does not like the "WriteString" command that I have. As you can see, it works if I use a statis string instead. Again, is this a bug, or am I doing something wrong?

Thanks in advance for any input on what the problem is.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 30th Dec 2011 09:36 Edited at: 30th Dec 2011 09:36
Quote: "//if GetFileExists("highscores.txt") > 0 then DeleteFile("HighScores.txt")"


You can replace this with OpenToWrite() as you say, and it works for me. I use this for debugging, so every AppGameKit program I have written does this every time it runs, and it has never failed me.
In your code I quoted here, you have used upper and lower case "S", maybe this is the problem? I have heard that file names in AppGameKit are case sensitive.

I haven't looked at your other code lines in the context of the entire program, but again this method works fine for me, there must be a bug in your code somewhere.

Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 30th Dec 2011 15:22
Quote: "I have heard that file names in AppGameKit are case sensitive."

Not on PC, but are in iOS, and Android. (Probably others too)

My signature is NOT a moderator plaything! Stop changing it!
badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 30th Dec 2011 17:51
I have had problems with upper and lower case in filenames, but not in this case. I know for a fact that the DeleteFile function works, it's the OpenToWrite function that does not. Again, I expect setting the "append" parameter to delete the file if it exists, and it's not. And that's what's causing the error, because if I delete the file using code, it works.

So, I'm thinking that it might be my computer, and not AGK. I noticed that when I delete the file and run the app, the file does not show up in the directory until I close the app. I'm running Windows Vista. Has anyone else come across this problem with Vista? Does it have anything to do with DEP?
badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 30th Dec 2011 19:02
I found part of the problem. I have to run the .exe as "administrator".

However, this does not solve my problem with the "WriteString". Anyone come across a problem like this?
badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 30th Dec 2011 19:15
Well, it must be a coding problem. I updated the b bottom of the code as follows:



So, I declared tString as a string at the top of the program and it worked. So, it must be something I am doing in my code.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 1st Jan 2012 18:25
One issue I see here is that you're attempting to write the file every loop rather than just when it changes. Your poor filesystem never gets a break

As to the write problem, I would suggest compiling the details into a string and writing the whole lot in one go using writeLine.

Reading and writing whole lines and splitting it up yourself may involve more work, but is better for validation and error checking of data as you read it.
badkneecap
14
Years of Service
User Offline
Joined: 21st Jun 2010
Location:
Posted: 1st Jan 2012 18:49
It's funny you say that, because I quickly realized that when I checked my CPU and fixed it. So, right now I just write to the file when a new high score comes in.

As far as the coding, I think you solution is about the same as the one I came up with. It seems to me there is a problem trying to use the "HiScores[x].init" directly in the "WriteString" function. If I build a string like you said and save the entire line as the concatenated string, then it's ultimately doing the same thing. But, it's a good alternative to the problem. Thanks.

Login to post a reply

Server time is: 2024-11-22 20:29:06
Your offset time is: 2024-11-22 20:29:06