Jump to content


Photo

Saving point records to a file.


  • Please log in to reply
9 replies to this topic

#1 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 06 July 2012 - 02:08 PM

Hiya! :)

I'm making a maths game which continuously asks multiplication sums for the player to type in the answers for until the in-game timer runs out. Each time the player scores correctly, the variable 'right' is increased by 1 and likewise for the variable 'wrong' upon answering incorrectly. Also, the variable 'points' increases or decreases after the user has submitted their answer and the variable 'currtime' has been configured to be the current computer time.

I now wish to save these stats (into the same file where the application is stored) into 'statistics.txt' if it exists, if not create it, noting all of the above. In the 'press <Escape>' event, which is the key I wish to close the game from, I have the following code:

stats = file_text_open_append('statistics.txt');
file_text_write_string(stats, string(currtime)+" -- Correct = "+string(right)+", Incorrect = "+string(wrong)+" & Points = "+string(points)); 
game_end();

I now create a 'Windows NSIS installer' for the game, extract it, go into <User>/<Game name> and open the application, score a few points and then press <Esc> which closes the game. I now look into the file where the application is but no 'statistics.txt' file has been created... What's going wrong?

:thanks:

KingD.
  • 0

#2 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 1464 posts
  • Version:GM8.1

Posted 06 July 2012 - 02:43 PM

the filename should be:
working_directory+'\statistics.txt'
  • 0

#3 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 06 July 2012 - 03:28 PM

Thanks for replying.

The only thing is, in the manual it gives the example:

--
Example :

mytxt = file_text_open_append( 'myfile.txt' );

This would open myfile.txt from the same directory as the game, setting it to the id mytxt.
--

which suggests that by using file_text_open_append(), it stores it in the same file as the application is located.

How would you locate a .txt file in the Desktop? (So that I only have to run the game rather than create an executable for it and to sort the initial issue out)

KingD.

Edited by KingDragonRider, 06 July 2012 - 03:28 PM.

  • 0

#4 jo-thijs

jo-thijs

    GMC Member

  • GMC Member
  • 1464 posts
  • Version:GM8.1

Posted 06 July 2012 - 03:38 PM

var temp;
temp=string_delete(working_directory,1,9);
temp="C:\Users\"+string_copy(temp,1,string_pos('\',temp)+"Desktop\statistics.txt";

this returns the filename of a savefile on your desktop and put it in the temporary variable temp.
  • 0

#5 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4714 posts
  • Version:GM8

Posted 06 July 2012 - 04:06 PM

You need to close the text file, if you haven't done that already.

var stats;
stats=file_text_open_append("statistics.txt");
file_text_write(stats,blahblahblah);
file_text_close(stats);
game_end();

Edited by TheouAegis, 06 July 2012 - 04:08 PM.

  • 0

#6 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 07 July 2012 - 08:36 AM

Urghhh... This is really bugging me now.

I really don't think it is anything wrong with the code, but here it is anyway:

stats = file_text_open_append("statistics.txt");
file_text_write_string(stats, string(currtime)+" -- correct: "+string(right)+", incorrect: "+string(wrong)+", points: "+string(points)+", lowest number: "+string(n1)+", highest number: "+string(n2)+", timer: "+string(global.timerstart)); 
file_text_writeln(stats);
file_text_close(stats);
game_end();

KingD.

Edited by KingDragonRider, 07 July 2012 - 12:40 PM.

  • 0

#7 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4714 posts
  • Version:GM8

Posted 07 July 2012 - 02:52 PM

Yeah, it looks fine to me. I don't use ftoa() so I'm not sure if the bug is there. It shouldn't be that, but simple test: change file_text_open_append() to file_text_open_write() and test that for me. Like I said, probably not the issue but everything after that is how i have it in my game.
  • 0

#8 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 07 July 2012 - 03:03 PM

Yeah, it looks fine to me. I don't use ftoa() so I'm not sure if the bug is there. It shouldn't be that, but simple test: change file_text_open_append() to file_text_open_write() and test that for me. Like I said, probably not the issue but everything after that is how i have it in my game.


Thanks for the reply :)

However what I want to achieve is a complete list that stores each game session in a line, so by using file_text_open_write, that erases all the other lines; but file_..._append adds onto the text document..
I have tried 'write' though, but still nothing appears to happen (aka, no .txt file shows up) and I am beginning to wonder if I need to look elsewhere for the text file rather than the application directory.

KingD.

Edited by KingDragonRider, 07 July 2012 - 03:04 PM.

  • 0

#9 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4714 posts
  • Version:GM8

Posted 07 July 2012 - 03:09 PM

Which version of GM? I think Studio or 8.1 stores it in %localappdata%\<Project Name>
  • 1

#10 KingDragonRider

KingDragonRider

    KDR Productions

  • GMC Member
  • 166 posts
  • Version:GM:Studio

Posted 07 July 2012 - 03:27 PM

Which version of GM? I think Studio or 8.1 stores it in %localappdata%\<Project Name>


I have Studio. I'll check that out ;)

EDIT: Thanks, this is what I wanted, although it only works for when you play it from Studio, as an external application it doesn't work.

KingD.

Edited by KingDragonRider, 07 July 2012 - 04:29 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users