array index problem

Posted By: hammeraxe

array index problem - 06/20/07 08:01

hi eveyone!

I have a problem: I've got an array buildings[300] but when it is called with an index bigger than 0 the engine crashes...

here is one example:

function filewr
{var filehandle;
var a;


a=0;
filehandle=file_open_write("buildings.txt");
while(a<=99)
{


file_var_write(filehandle,buildings[0*100+a]);
file_var_write(filehandle,buildings[ 1*100+a]);
file_var_write(filehandle,buildings[ 2*100+a]);
a+=1;
wait(1);
}
file_close (filehandle);
}
Posted By: Xarthor

Re: array index problem - 06/20/07 08:15

Make sure that you really have the line:
var buildings[300];

and no var or any other object that is named "buildings" too.

This code is working perfectly for me:
Code:

var buildings[300];



function save_array()
{
var fhandle;
var i;

fhandle = file_open_write("save.txt");
i = 0;

while(i < 100)
{
file_var_write(fhandle,buildings[0*100 + i]);
file_var_write(fhandle,buildings[1*100 + i]);
file_var_write(fhandle,buildings[2*100 + i]);

i += 1;
}

file_close(fhandle);

// error("Array saved");
}


Posted By: Anonymous

Re: array index problem - 06/20/07 08:16

must be the array-declaration (the code seems ok)

var buildings[300]; // global var
Posted By: hammeraxe

Re: array index problem - 06/20/07 08:35

ahhhhhhhhhhhh....

i'm a real idiot...

i had

var buildings(300) not [300]


thanks
© 2024 lite-C Forums