Does something like this work??

Click to reveal..

Code:
var file_handle = 0;
var file_data = 99999;
total_vertices = ent_status(entNewTerrain,0);		
if(file_exists("file_name")) // previously saved data exists?
{ 	
var index = 0;
file_handle = file_open_read("file_name");			
while(file_data) // then load the previously stored height values and apply them to the terrain
{
file_data = file_var_read(file_handle);
if(!file_data);
break;
 				// no need to load the x and y coordinates of the terrain - they can't be changed
vec_to_mesh(vector (0, 0,file_data), entNewTerrain, index);
index += 1;
				
}
}



EDIT* I think I set the starting value of file_data out of range so I made it a small value.. Some other fixes to.


you could also do ...
Code:
var file_handle = 0;
var file_data = 99999;
total_vertices = ent_status(entNewTerrain,0);		
if(file_exists("file_name")) // previously saved data exists?
{ 	
var index = 0;
file_handle = file_open_read("file_name");		

while(index<total_vertices)
{
terrain_value[index] = file_var_read(file_handle);
index +=1
}

index =0;
	
while(index< total_vertices) // then load the previously stored height values and apply them to the terrain
{
 				// no need to load the x and y coordinates of the terrain - they can't be changed
vec_to_mesh(vector (0, 0,terrain_value[index]), entNewTerrain, index);
index += 1;
				
}
}



EDIT LAST* JustSid was great enough to turn my primitive code into yet another brilliantly simple piece of code art..
see below.

Code:
void bar()
{
	var i, file_data, file_handle;

	file_handle = file_open_read("filename");
	if(file_handle) // Check if the file exist, if not, the file handle is going to be 0
	{
		for(i=0;; i++) // for loops don't need a condition, this will work fine
		{
			file_data = file_var_read(file_handle);
			if(!file_data)
				break;

			vec_to_mesh(vector(0, 0, file_data), entity, i);
		}
                file_close(file_handle);
	}
}



THANK YOU JustSid !

Edit2020283* JustSid reminded me that the code needs a file_close(); for memory reasons so I just dropped one in. It might not be the best place for it.

Last edited by Malice; 06/16/13 00:23.