Ok, I have another problem when im trying to save tiledata to a file.
if (keycode == eKeyF5) {
File *output = File.Open("tiles.dat",eFileWrite);
if (output == null) Display("Error opening file.");
else {
int tx = 0; int ty = 0;
while (ty < 15) {
while (tx < 20) {
output.WriteInt(tiles[ty].x[tx]);
tx++;
}
ty++;
}
output.Close();
}
}
if (keycode == eKeyF6) {
File *input = File.Open("tiles.dat",eFileRead);
if (input == null) Display("Error opening file.");
else {
int tx = 0; int ty = 0;
while (ty < 15) {
while (tx < 20) {
tiles[ty].x[tx] = input.ReadInt();
tx++;
}
ty++;
}
input.Close();
}
}
It should work that pressing f5 saves tiles[].x[] to tiles.dat and f6 loads the stored data back to tiles[].x[]. But from some reason when I load the stored data, only first row of the data is returned (that means tiles[0].x[from 0 to 20]). Values in tiles[1].x[], tiles[2].x[]... are 0. Code is short and simple so the problem should be easy to fiqure out but i just dont see it.
tiles[].x[] is like this:
struct TileDataSt {
int x[20];
};
TileDataSt tiles[15];
Please use the [code=AGS] tag to format your code. I've edited your post for you.
I don't see it either. Just put in a couple of Display commands like this ...
if (keycode == eKeyF5) {
File *output = File.Open("tiles.dat",eFileWrite);
if (output == null) Display("Error opening file.");
else {
int tx = 0; int ty = 0;
while (ty < 15) {
while (tx < 20) {
output.WriteInt(tiles[ty].x[tx]);
tx++;
// Try this to see what your code is actually doing
Display("tiles[%d].x[%d]=%d",ty,tx,tiles[ty].x[tx]);
}
ty++;
}
output.Close();
}
}
Thanks, that helped. I simply forgot to reset "tx" value after each "ty" cycle :)
Quote from: RickJ on Sat 13/07/2013 16:58:38Just put in a couple of Display commands
In lieu of a more robust debugger, this is often one of the most useful debugging techniques AGS offers. Ensuring that the code is called, printing variable values, and various other tasks are greatly simplified thanks to this command and usage.