Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (ozgur, degenerate_762), 1,455 guests, and 10 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Senior Member
NeoNeper  Offline 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!

Code:
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

M
Malice
Unregistered
Malice
Unregistered
M



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.
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 Offline OP
Senior Member
NeoNeper  Offline 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

M
Malice
Unregistered
Malice
Unregistered
M



Bumped so you see all the after-edits

Re: Terrain Save vertex in TXT and LOAD! Doubt [Re: ] #424435
06/16/13 00:28
06/16/13 00:28
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Btw. vec_for/to_mesh is outdated syntax (esp. when you work with terrains) and will not be supported in the future, use ent_get/set_vertex instead!


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
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 Offline OP
Senior Member
NeoNeper  Offline OP
Senior Member

Joined: Nov 2007
Posts: 318
Brasil, Paraná
Tanks Malice and SUPERKU.
Its work FINE.

SAVE TERRAIN VERTEX (z)
Code:
...
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)

Code:
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

M
Malice
Unregistered
Malice
Unregistered
M



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 Offline
Expert
Uhrwerk  Offline
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...
Re: Terrain Save vertex in TXT and LOAD! Doubt [Re: Uhrwerk] #435930
01/16/14 10:49
01/16/14 10:49
Joined: May 2005
Posts: 868
Chicago, IL
Dooley Offline
User
Dooley  Offline
User

Joined: May 2005
Posts: 868
Chicago, IL
file_exists is not recognized by my version. I am using A7.80 Commercial. Is this a new command for A8?

Re: Terrain Save vertex in TXT and LOAD! Doubt [Re: Dooley] #435933
01/16/14 10:54
01/16/14 10:54
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
I already told you in your other thread that this is an A7 function (and that you need to update your version).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1