Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (dr_panther, Ayumi, 7th_zorro), 877 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Reading int or float values from a file [Re: EvilSOB] #340512
09/04/10 20:38
09/04/10 20:38
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
Hi,

I am back - and my problems, too. laugh

@EvilSOB - I have tested it and it works. But I recognized, that it`s not enough. Of course, I will create an original higscore list and I forgot the player names. So only a value is not enough - THX.

@JustSid - You script is still, that what I want and still with "Kanonen auf Spatzen". I took a look to a few Source-Files and I am sure, I will need maximum one or two of them. There is so much stuff to be installed, which is not needed and what I don`t know what it does.

Re: Reading int or float values from a file [Re: Ditje] #340515
09/04/10 21:11
09/04/10 21:11
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
I'm sorry, but there is no Lite Foundation script file that isn't needed for my high score example =/

Quote:

There is so much stuff to be installed, which is not needed and what I don`t know what it does.

Uhm, you don't need to install anything to use Lite Foundation and like I said, all things are used (but mostly transparent in the background). However, Lite Foundation does nothing that it shouldn't and it should be safe to use it.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Reading int or float values from a file [Re: WretchedSid] #340521
09/04/10 23:17
09/04/10 23:17
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Try this then... And its designed to work with DOUBLES instead of floats.

Click to reveal..
Code:
#include <litec.h>
#include <default.c>
#define PRAGMA_PATH "@Bits"



void main()
{


	STRING* highscore_name 	= str_create("player name");
	double  highscore 		= 1000000000;
	// highscore save
	var highscore_handle;
	highscore_handle = file_open_write("highscores.txt");
		file_str_write(highscore_handle,   highscore_name	);
			file_str_write(highscore_handle, ",");
		file_str_writeto(highscore_handle, (char*)&highscore, 8	);
	file_close(highscore_handle);
	
	
	STRING* highscore2_name = str_create("");
	double  highscore2 		= 0;
	// highscore load
	var highscore_handle;		STRING* tmp = str_create("#9");
	highscore_handle = file_open_read ("highscores.txt");
		file_str_read(highscore_handle, highscore2_name);
		file_chr_read(highscore_handle, tmp);	memcpy(&highscore2, tmp.chars, 8);
	file_close(highscore_handle);
	


	
	STRING* tmp1 = str_create("");		str_for_float(tmp1, highscore);
	STRING* tmp2 = str_create("");		str_for_float(tmp2, highscore2);
	
	while(1)
	{
		draw_text("Score SAVED  =", 10,10, vector(100,100,100));
			draw_text(highscore_name, 180,10, vector(100,100,100));
			draw_text(tmp1, 300,10, vector(100,100,100));
	
		draw_text("Score LOADED =", 10,40, vector(100,100,100));
			draw_text(highscore2_name, 180,40, vector(100,100,100));
			draw_text(tmp2, 300,40, vector(100,100,100));
		
		wait(1);
	}

}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Reading int or float values from a file [Re: EvilSOB] #340542
09/05/10 13:36
09/05/10 13:36
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
I am getting on. If I use file_open_append instead of file_open_write, I can add new entries to the file.

DOUBLES seems to be the only possiblity. I checked other types, too laugh If I take a look to the textfile the DOUBLE values are crypted.

I understood that
it`s done by
file_str_writeto(highscore_handle, (char*)&highscore, 8 );
and "redone" by
file_chr_read(highscore_handle, tmp); memcpy(&highscore2, tmp.chars, 8);

Can you please explain what happens? laugh

THX Ditje

@Sid - it`s nothing about trust laugh I have send you a PM.

Re: Reading int or float values from a file [Re: Ditje] #340547
09/05/10 14:11
09/05/10 14:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
No problem.

file_str_writeto(highscore_handle, (char*)&highscore, 8 );
"file_str_writeto" is meant for writing STRING or char* data.
So by telling it to write "(char*)&highscore, 8", I have told it that
there is a char* block at the same address as the double we want to send,
and that the block is 8 bytes long (the size of a double).
So it then writes the 8 bytes of our double as an 8 byte 'string'.

file_chr_read(highscore_handle, tmp); memcpy(&highscore2, tmp.chars, 8);
"file_chr_read" reads char* data into a string. So I create "tmp" 9 bytes long,
which is one byte longer than the length of a double. The extra byte is to
allow for the null character (created by the "file_str_writeto") in the file.
So our data is read out of the file and stored in the "tmp" string.
I then use memcpy to copy that data (from the tmp.chars location)
and store it in our finishing double variable.
The "tmp" string is no longer needed, so it can now be re-used if you are
going to be reading more doubles.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Reading int or float values from a file [Re: EvilSOB] #340550
09/05/10 14:41
09/05/10 14:41
Joined: Jul 2010
Posts: 127
Germany, Herford
Ditje Offline OP
Member
Ditje  Offline OP
Member

Joined: Jul 2010
Posts: 127
Germany, Herford
Thank you very much - very detailed. I will try now, to get the complete List into vars laugh

Ditje

Page 2 of 2 1 2

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