2 registered members (ozgur, degenerate_762),
1,455
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Terrain Save vertex in TXT and LOAD! Doubt - SOLVED
#424427
06/15/13 19:27
06/15/13 19:27
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
Hi brothers!. currently I'm using the following function to save coordinateS (Z) of all vertices of my Terrain!
total_vertices = ent_status(entNewTerrain,0);
if(game_load(name, 1) > 0) // previously saved data exists?
{
var 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_values_i[index]), entNewTerrain, index);
index += 1;
}
}
This function works well but does not like to use game_load. When I make any changes in the script, the data saved as game_save not work. So I'm saving this data in a TEXT file. The difficulty in this case is on recovering this data. Could someone give me a hand please?
Last edited by NeoNeper; 06/16/13 19:42.
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
Re: Terrain Save vertex in TXT and LOAD! Doubt
[Re: NeoNeper]
#424429
06/15/13 20:34
06/15/13 20:34
|
Malice
Unregistered
|
Malice
Unregistered
|
Does something like this work??
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 ...
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.
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.
|
|
|
Re: Terrain Save vertex in TXT and LOAD! Doubt
[Re: ]
#424431
06/15/13 20:53
06/15/13 20:53
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
TAAAAAANKS Malice. I go test!
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
Re: Terrain Save vertex in TXT and LOAD! Doubt
[Re: NeoNeper]
#424434
06/16/13 00:24
06/16/13 00:24
|
Malice
Unregistered
|
Malice
Unregistered
|
Bumped so you see all the after-edits
|
|
|
Re: Terrain Save vertex in TXT and LOAD! Doubt
[Re: Superku]
#424465
06/16/13 17:24
06/16/13 17:24
|
Joined: Nov 2007
Posts: 318 Brasil, Paraná
NeoNeper
OP
Senior Member
|
OP
Senior Member
Joined: Nov 2007
Posts: 318
Brasil, Paraná
|
Tanks Malice and SUPERKU. Its work FINE. SAVE TERRAIN VERTEX (z)
...
if(file_exists("tsave.txt"))
{
int index;
var filehandle = file_open_write("tsave.txt");
total_vertices = ent_status(terrain_level1,0);
CONTACT* c;
while(index <= total_vertices)
{
c = ent_getvertex(terrain_level1,NULL,index);
file_var_write(filehandle,c.z);
index ++;
}
file_close(filehandle); // the file now contains "123456.789 1.414 "
}
...
LOAD TERRAIN VERTEX (z)
if(file_exists("tsave.txt"))
{
var i, file_data, file_handle;
file_handle = file_open_read("tsave.txt");
CONTACT* c;
if(file_handle) // Check if the file exist, if not, the file handle is going to be 0
{
for(i=0; i <= total_vertices; i++) // for loops don't need a condition, this will work fine
{
file_data = file_var_read(file_handle);
c = ent_getvertex(terrain_level1,NULL,i);
c.v = NULL;
c.z = file_data;
ent_setvertex(terrain_level1,c,i);
}
file_close(file_handle);
}
}
Please! Use easy words to be translated. because my English is not very good! Grateful. _______________________________________________________
|
|
|
Re: Terrain Save vertex in TXT and LOAD! Doubt
[Re: NeoNeper]
#424467
06/16/13 17:49
06/16/13 17:49
|
Malice
Unregistered
|
Malice
Unregistered
|
if(file_exist(...)) and if (file_handle) are redundant... if(file_exist()) means file handle should always be true. Also if(file_handle) is true then the file exist...
EDIT* Oh yeah your welcome, but JustSid and Superku did the real magic here.
Last edited by Malice; 06/16/13 17:50.
|
|
|
Re: Terrain Save vertex in TXT and LOAD! Doubt
[Re: ]
#424474
06/16/13 20:22
06/16/13 20:22
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
file_exists means that a file exists.
The handle returned by file_open_* also says if the file could be opened.
You can also have a file that you cannot open, for instances because of missing privileges or because another process is using it.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
|