Config Files?


Quiest

I like turtles!
Joined
Sep 2, 2004
Messages
3,411
Age
40
Location
Dteuschland ;)
Hi!

I like to make saveable config and highscores for my game.
So how do you read and write variables out of and into a text file?
Or how else is it done?

Thanks in advance!
 
You can save and load with the, yes, save() and load() commands. Saveble are structs and arrays, an example will probably help more than words:)

Code:
GLOBAL
array[10];

BEGIN
array[0] = 23;
array[7] = 12;
save("config.cfg",array,sizeof(array));
END
Writes the array to that file, to be loaded:

Code:
GLOBAL
array[10];

BEGIN
load("config.cfg",array);
write_int(0,0,0,0,&array[0]);
write_int(0,0,10,0,&array[7]);
END
Would write 23 and 12 to the screen.

Nice game(Two Sided), just played it :) is there no way to go back from the options screen or have i overlooked it? And I wasn't able to change the difficulty?
 
Ppush b to get back to the main menu, left if you want to go out of the music "submenu".
And, yes, there is no way to change the difficulty yet.
Oh and it`s Two-Sider (not Sided) :D

Thanks for your help!


Now I have to implement a sorting algorithm for the highscore array.
<sarcasm>Yippie!</sarcasm>
What`s the easiest? I`m currently thinking of BubbleSort for only a array
with the size of ten (that should be enough for highscores).

EDIT: Oh, I don`t have to name it array[10], I can go for highscore[10] and config[2], right?
 
I'd put it in one array to have it in one file, but yeah, name it any way you want :)

And for a 10 position(0-9)highscore table, assuming a lower index means a higher value:
Code:
GLOBAL
highscore[9];

PROCESS addScore(int score)

BEGIN

while(x<10)
  if(highscore[x]<score)
    break;
  end
  x++;
end

z = x;

while(x<9)
  highscore[x+1] = highscore[x];
  x++;
end 
 
highscore[z] = score;

END

Not tested, should work though if the array isn't out of order to begin with. Might give you some inspiration :)
 
Oh, I found one of my exercise sheets from last semester in which we had to implement Bubble Sort into mips assembler code.

I think I work with that, it looks much shorter.
But if it doesn`t work, I`m glad I can come back to try your code.
So thanks, Moogle! :D

BTW, is there any (fenix) work of yours to try? You really know a lot about fenix!
 
Yay, my fenix bubblesort test! It works!

Code:
program bubblesorttest;

global

n=9;
i=1;
t;
j;
array[9];

begin
 
 j=i+1;
 
 array[1]=7;
 array[2]=3;
 array[3]=4;
 array[4]=9;
 array[5]=1;
 array[6]=8;
 array[7]=2;
 array[8]=5;
 array[9]=6; 
 
 while(i<=n);
  while(j<=n);  
   if(array[i]<array[j])    
    t=array[j];                  
    array[j]=array[i];           
    array[i]=t;                  
   end;    
   j++;                            
  end;  
  j=i+1;
  i++;                               
 end;
 
 save("high.cfg",array);
 
 array[1]=0;
 array[2]=0;
 array[3]=0;
 array[4]=0;
 array[5]=0;
 array[6]=0;
 array[7]=0;
 array[8]=0;
 array[9]=0;
 i=1;
 load("high.cfg",array);
 
 loop
  while(i<10)
   write_int(0,20,i*10,0, &array[i]);
   i++;
  end;
  frame;
 end;
end;

After looking at your code again (MoogleSort :D ), I think it`s mostly the same...
 
Mine doesn't sort, it just inserts a new value and moves everything below one place down :)

Work of me, hm, for the GP32 there practically isn't any, currently working on a pc game though, I'll show it in due time:) Do have some screenshots/downloads of earlier projects. And of course there are those 4 fully documented sources here in the File Archive.
 
Quiest posted on Mar 3 2005 at 08:37 PM said:
Yay at my fenix bubblesort test! It works!

Code:
program bubblesorttest;

global

n=9;
i=1;
t;
j;
array[9];

begin
 
 j=i+1;
 
 array[1]=7;
 array[2]=3;
 array[3]=4;
 array[4]=9;
 array[5]=1;
 array[6]=8;
 array[7]=2;
 array[8]=5;
 array[9]=6; 
 
 while(i<=n);
  while(j<=n);  
   if(array[i]<array[j])    
    t=array[j];                  
    array[j]=array[i];           
    array[i]=t;                  
   end;    
   j++;                            
  end;  
  j=i+1;
  i++;                               
 end;
 
 save("high.cfg",array);
 
 array[1]=0;
 array[2]=0;
 array[3]=0;
 array[4]=0;
 array[5]=0;
 array[6]=0;
 array[7]=0;
 array[8]=0;
 array[9]=0;
 i=1;
 load("high.cfg",array);
 
 loop
  while(i<10)
   write_int(0,20,i*10,0, &array[i]);
   i++;
  end;
  frame;
 end;
end;

After looking at your code again (MoogleSort :D ), I think it`s mostly the same...

Just a programming tip for code optimisation, you can change the two lines:
j= i+1;
i++

To:
j=++i;

So increment i by 1 and set j to i.
(Doing "j=i++;" would set j to i, then increment i by 1)

Gaz.
 
Last edited by a moderator:
Thanks, but this is an error in my code, it must be

i++;
j=i+1;

because j has to be larger than i by 1.

It works both ways but needs more time (yeah not really much more, but more), since the while loops repeat more often than it needs to.
 
Back
Top