1. save and load sequences ??
- Posted by Gene Mannel <mgene2 at GJ.NET> Sep 12, 2000
- 406 views
- Last edited Sep 13, 2000
Hi Folks Ive got a game almost done but Im trying to add running score that saves to disk file. I want to use the following sequence for my scores: sequence TopTen TopTen = repeat({"NoName", 0} ,10)--This will be what it starts out with Ive been able to save it to disk but reading it back has been a challenge for me. Ive been saving it as a text file and reading it like such. for x = 1 to 10 TopTen[x][1] --The text comes up fine TopTen[x][2] --but the numbers dont come out right end for I read and tried to understand The mydata.ex file in the Demo directory but it is hard for me to follow. Any help here would be appreciated. Thank you Gene
2. Re: save and load sequences ??
- Posted by irv <irv at ELLIJAY.COM> Sep 12, 2000
- 379 views
- Last edited Sep 13, 2000
On Tue, 12 Sep 2000, you wrote: > Hi Folks > > Ive got a game almost done but Im > trying to add running score that saves to disk file. > > I want to use the following sequence for my scores: > > sequence TopTen > TopTen = repeat({"NoName", 0} ,10)--This will be what it starts out with > > Ive been able to save it to disk > but reading it back has been a challenge for me. > Ive been saving it as a text file and reading it like such. > for x = 1 to 10 > TopTen[x][1] --The text comes up fine > TopTen[x][2] --but the numbers dont come out right > end for > > I read and tried to understand The mydata.ex file > in the Demo directory but it is hard for me to follow. > > Any help here would be appreciated. > > Thank you > Gene --Tested code: include get.e atom fn object topten include get.e atom fn object topten topten = repeat({"NaName",0},10) fn = open("scores","w") print(fn,topten) close(fn) topten = {} fn = open("scores","r") topten = get(fn) topten = topten[2] for i = 1 to length(topten) do printf(1,"Name: %s Score: %d\n",topten[i]) end for topten = repeat({"NaName",0},10) fn = open("scores","w") print(fn,topten) close(fn) topten = {} fn = open("scores","r") topten = get(fn) topten = topten[2] for i = 1 to length(topten) do printf(1,"Name: %s Score: %d\n",topten[i]) end for -- Regards, Irv
3. Re: save and load sequences ??
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 13, 2000
- 395 views
<giggle!> Of course, Irv's "tested" code should have one of the duplicated > include get.e > atom fn > object topten at the beginning removed so it can actually run :) Dan ----- Original Message ----- From: "irv" <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Tuesday, September 12, 2000 8:23 PM Subject: Re: save and load sequences ?? > On Tue, 12 Sep 2000, you wrote: > > Hi Folks > > > > Ive got a game almost done but Im > > trying to add running score that saves to disk file. > > > > I want to use the following sequence for my scores: > > > > sequence TopTen > > TopTen = repeat({"NoName", 0} ,10)--This will be what it starts out with > > > > Ive been able to save it to disk > > but reading it back has been a challenge for me. > > Ive been saving it as a text file and reading it like such. > > for x = 1 to 10 > > TopTen[x][1] --The text comes up fine > > TopTen[x][2] --but the numbers dont come out right > > end for > > > > I read and tried to understand The mydata.ex file > > in the Demo directory but it is hard for me to follow. > > > > Any help here would be appreciated. > > > > Thank you > > Gene > > --Tested code: > include get.e > atom fn > object topten > include get.e > atom fn > object topten > > topten = repeat({"NaName",0},10) > fn = open("scores","w") > print(fn,topten) > close(fn) > > topten = {} > > fn = open("scores","r") > topten = get(fn) > topten = topten[2] > for i = 1 to length(topten) do > printf(1,"Name: %s Score: %d\n",topten[i]) > end for > topten = repeat({"NaName",0},10) > fn = open("scores","w") > print(fn,topten) > close(fn) > > topten = {} > > fn = open("scores","r") > topten = get(fn) > topten = topten[2] > for i = 1 to length(topten) do > printf(1,"Name: %s Score: %d\n",topten[i]) > end for > -- > Regards, > Irv
4. Re: save and load sequences ??
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 13, 2000
- 393 views
And here is a very slightly improved version of Irv's solution. Dan <begin improved code> --Tested code: -- SAVE BUNCHES OF TEXT AND NUMBERS TO FILE AND READ IT BACK include get.e --need it for the "get()" function to read whole file at once atom fn object topten -- CREATE 10 INITIAL DUMMY NAMES AND ZERO'D SCORES & WRITE THEM TO FILE: topten = repeat({"NaName",0},10) fn = open("scores","w") print(fn,topten)-- write them to file close(fn) -- READ THE SCORE FILE BACK & SHOW IT: puts(1,"original scores\n") topten = {} fn = open("scores","r") topten = get(fn) -- read entire score file into one sequence(object) topten = topten[2]--assume success (success state returned in [1]), get file -- each element in the sequence is one name/score pair for i = 1 to length(topten) do printf(1,"Name: %s Score: %d\n",topten[i]) -- show name/scores end for puts(1,"\n") -- spacer line -- UPDATE A SCORE & SAVE IT: topten[5][1] = "somebody" topten[5][2] = 50 fn = open("scores","w") print(fn,topten) close(fn) -- LOOK AT SCORES AGAIN & SHOW THEM AGAIN: puts(1,"UPDATED SCORES\n") topten = {} fn = open("scores","r") topten = get(fn) topten = topten[2] for i = 1 to length(topten) do printf(1,"Name: %s Score: %d\n",topten[i]) end for -- <end improved code> ----- Original Message ----- From: "irv" <irv at ELLIJAY.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Tuesday, September 12, 2000 8:23 PM Subject: Re: save and load sequences ?? > On Tue, 12 Sep 2000, you wrote: > > Hi Folks > > > > Ive got a game almost done but Im > > trying to add running score that saves to disk file. > > > > I want to use the following sequence for my scores: > > > > sequence TopTen > > TopTen = repeat({"NoName", 0} ,10)--This will be what it starts out with > > > > Ive been able to save it to disk > > but reading it back has been a challenge for me. > > Ive been saving it as a text file and reading it like such. > > for x = 1 to 10 > > TopTen[x][1] --The text comes up fine > > TopTen[x][2] --but the numbers dont come out right > > end for > > > > I read and tried to understand The mydata.ex file > > in the Demo directory but it is hard for me to follow. > > > > Any help here would be appreciated. > > > > Thank you > > Gene > > --Tested code: > include get.e > atom fn > object topten > include get.e > atom fn > object topten > > topten = repeat({"NaName",0},10) > fn = open("scores","w") > print(fn,topten) > close(fn) > > topten = {} > > fn = open("scores","r") > topten = get(fn) > topten = topten[2] > for i = 1 to length(topten) do > printf(1,"Name: %s Score: %d\n",topten[i]) > end for > topten = repeat({"NaName",0},10) > fn = open("scores","w") > print(fn,topten) > close(fn) > > topten = {} > > fn = open("scores","r") > topten = get(fn) > topten = topten[2] > for i = 1 to length(topten) do > printf(1,"Name: %s Score: %d\n",topten[i]) > end for > -- > Regards, > Irv
5. Re: save and load sequences ??
- Posted by Gene Mannel <mgene2 at GJ.NET> Sep 13, 2000
- 384 views
Hi again I see what I was doing wrong now. I was trying to send the the sequence using puts(fn, topten) instead of using print(fn, topten) It all seems to work now, 'puts' saves in an incorrect format which was making my hair fall out trying to figure it out. Thanks a bunch, Gene