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
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Quad), 608 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Get a line in a file [Re: JGGamer] #305762
01/17/10 02:59
01/17/10 02:59
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
Ok. It's working. I just need to get one last piece right.
The words are all joined, so I need to put a comma in between, and preferably drop each word one line down. Which means I have to have a string like this: ",\n". But I don't seem to know how to do it right, because i get an error with this line:
str_cat(newString,WordText+",\n"); ...in this code:

Code:
myFile = file_open_read(fileString);
	if(myFile == 0) {fileOpen = 0;}
	var i = 0;
	while (i < 91)
	{
		file_str_read(myFile,WordText);
		str_cat(newString,WordText+",\n");
		str_cpy((testing.pstring)[0], WordText);
		i += 1;
		if (i >= 91) 
		{
			file_close(myFile);
			fileOpen = 0; 
			myFile = file_open_write(fileStringCopy);
			file_str_write(myFile,newString);
			file_close(myFile);
			break;
		}
		wait(1);
	}



I searched the manual, but found nothing to help me.

Re: Get a line in a file [Re: JGGamer] #305765
01/17/10 04:21
01/17/10 04:21
Joined: Jul 2004
Posts: 1,710
MMike Offline
Serious User
MMike  Offline
Serious User

Joined: Jul 2004
Posts: 1,710
use the line feed of c++? not the \n try
"\\n"

or "\r" or even better "\r\n" carriage return

Last edited by MMike; 01/17/10 04:25.
Re: Get a line in a file [Re: MMike] #305882
01/18/10 04:54
01/18/10 04:54
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
I don't think '\n' is the problem. The issue is how to make a line when using a pointer (For example, wordText - which is a string, and then a code to tell the engine to drop to the next line). When I was using python, it was simply a matter of adding +"\n", which doesn't work with lite-c. If someone has info on this, I would be glad to have it.

Anyway... Great News! I found the solution! A simple way to delete a line in the file by copying of course.

Here's the code:


Code:
//Don't forget to declare the variables.

action recheck() //******THIS IS NOT IMPORTANT - just to see if I could use the copy.
{
	myFile = file_open_append(fileStringCopy);
	if(myFile == 0) {fileOpen = 0;}
	else
	{
		fileOpen = 1;
		var i;
		for (i=0; i<lineToRead; i++)
		{
			file_str_read(myFile,WordText);
			str_cpy((testing.pstring)[0], WordText);
		}
		file_close(myFile); fileOpen = 0;
	}
}

action replaceFile()
{
	myFile1 = file_open_read(fileString); //open file 1
	myFile2 = file_open_append(fileStringCopy); //open file 2
	if (myFile1 == 0) {fileOpen = 0;}
	var ii = 0;
	var skipLine = 0;
	while (ii < 91)
	{
		ii += 1;
		//when the line is reached...
		if (skipLine == 0 && ii == lineToRead) {skipLine = 1;} //...indicate
		file_str_read(myFile1,WordText); //read a line from file 1
		if (skipLine != 1) //as long as the line is not read...
		{
			str_cpy(newString,WordText); //...copy
			file_str_write(myFile2,newString); //...write a line to file 2
			file_str_write(myFile2,","); //place a comma after
		}
		str_cpy((testing.pstring)[0], newString); //check word on screen
		if (skipLine == 1) {skipLine = 2;} // indicate that the line is read
		if (ii >= 91) //when all lines are read...
		{
			file_close(myFile1); //close files
			file_close(myFile2);
			fileOpen = 0; 
			ent_remove(me); //remove temporary entity
			temp = ent_create("mark.mdl",vector(0,0,0),recheck);
			break; //stop the loop
		}
		wait(1);
	}
}

action copyFile() //******THIS IS NOT IMPORTANT - just a copy to string
{
	myFile = file_open_read(fileString);
	if(myFile == 0) {fileOpen = 0;}
	var i = 0;
	while (i < 91)
	{
		file_str_read(myFile,WordText);
		str_cat(newString,WordText); //copy the entire file to a string
		str_cat(newString,",");
		str_cpy((testing.pstring)[0], WordText);
		i += 1;
		if (i >= 91) 
		{
			file_close(myFile);
			fileOpen = 0; 
			ent_remove(me); //remove temporary entity
			temp = ent_create("mark.mdl",vector(0,0,0),replaceFile);
			break;
		}
		wait(1);
	}
}

//Get the word in the line
myFile = file_open_read(fileString);
if(myFile == 0) {fileOpen = 0;}
else
{
	fileOpen = 1;
	var i;
	for (i=0; i<lineToRead; i++)
	{
		file_str_read(myFile,WordText);
		str_cpy((Word.pstring)[0], WordText);
		str_cpy(theWord,WordText);
	}
	file_close(myFile); fileOpen = 0;
	temp = ent_create("mark.mdl",vector(0,0,0),copyFile);
}



In order to just use two files for copying, I copy the original using 'file_cpy', and use that file to read from (file 1). After the second file has been created (file 2), I clear file 1 by using 'file_open_write ("")'. It should be empty now, so then I can use that to copy from file 2. So I would be copying back and forth between those two files.
I feel good about this, because now I have a better feel on using files. I'm still interested in dropping a line though. It's not so important now, but it might come in handy later. So if anyone has some input, please post it. Thanks for all the help.

Last edited by JGGamer; 01/18/10 04:57.
Re: Get a line in a file [Re: JGGamer] #305886
01/18/10 06:50
01/18/10 06:50
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
You want to get a new line while writing in your file, right?
I think it's the same like '\r\n', but I use this sometimes:
Code:
file_asc_write(hndFile,13);
file_asc_write(hndFile,10);



Re: Get a line in a file [Re: GorNaKosh] #305934
01/18/10 15:40
01/18/10 15:40
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
Yes! '\r\n' works! Thanks.
Sorry MMike, I hadn't tried that one. Mission complete - Thanks.

Re: Get a line in a file [Re: JGGamer] #305936
01/18/10 16:01
01/18/10 16:01
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
Ah. I think I better address this now, because i may need to use it.

Let's say I have a string pointer - STRING* name = "#40";
Now I want to place a message at runtime - str_cpy((message.pstring)[0], name "has the ball");

How do I connect the string pointer 'name' to the string 'has the ball', so that I can change 'has the ball' to anything I want during the game, while 'name' (whatever name is used) remains the same?

Re: Get a line in a file [Re: JGGamer] #305954
01/18/10 17:14
01/18/10 17:14
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
Oh dear... and I made a mistake. I forgot to change append to write in the code. Sorry. It should be file_open_write instead of file_open_append:

Code:
action replaceFile()
{
	myFile1 = file_open_read(fileString); //open file 1
	myFile2 = file_open_write(fileStringCopy); //open file 2
	if (myFile1 == 0) {fileOpen = 0;}
	var ii = 0;
	var skipLine = 0;
	while (ii < 91)
	{
		ii += 1;
		//when the line is reached...
		if (skipLine == 0 && ii == lineToRead) {skipLine = 1;} //...indicate
		file_str_read(myFile1,WordText); //read a line from file 1
		if (skipLine != 1) //as long as the line is not read...
		{
			str_cpy(newString,WordText); //...copy
			file_str_write(myFile2,newString); //...write a line to file 2
			file_str_write(myFile2,","); //place a comma after
		}
		str_cpy((testing.pstring)[0], newString); //check word on screen
		if (skipLine == 1) {skipLine = 2;} // indicate that the line is read
		if (ii >= 91) //when all lines are read...
		{
			file_close(myFile1); //close files
			file_close(myFile2);
			fileOpen = 0; 
			ent_remove(me); //remove temporary entity
			temp = ent_create("mark.mdl",vector(0,0,0),recheck);
			break; //stop the loop
		}
		wait(1);
	}
}



Re: Get a line in a file [Re: JGGamer] #306026
01/19/10 05:47
01/19/10 05:47
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
to extend the string 'name' you have to use str_cat() if you need the name seperatly in your script again you could use an other temporary string like this:
Code:
//[...]
STRING *strTemp = str_create("#999");
str_cpy(strTemp, name);
str_cat(strTemp, "has the ball");
str_cpy((message.pstring)[0], strTemp);
str_remove(strTemp);



Last edited by GorNaKosh; 01/19/10 05:48.
Re: Get a line in a file [Re: GorNaKosh] #306256
01/20/10 19:49
01/20/10 19:49
Joined: Nov 2008
Posts: 109
J
JGGamer Offline OP
Member
JGGamer  Offline OP
Member
J

Joined: Nov 2008
Posts: 109
Ah... append. Didn't think about that. Thanks.

One final thing - I hope. How do I convert a variable to a string? I found this in the manual, but I'm not sure how to use it. var_for_name("myVariable = 400"));

Re: Get a line in a file [Re: JGGamer] #306259
01/20/10 20:19
01/20/10 20:19
Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
GorNaKosh Offline
Junior Member
GorNaKosh  Offline
Junior Member

Joined: Feb 2009
Posts: 84
Deutschland/Niedersachsen
Möp Fail grin ... try str_for_num()

Page 2 of 3 1 2 3

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