Map cycle with FRIK_FILE?

Discuss programming in the QuakeC language.
Post Reply
Orion
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Map cycle with FRIK_FILE?

Post by Orion »

Hey, I'm kind of a noob with FRIK_FILE, and I don't know if there's already a similar topic, but I would like to do this: make a list of all maps I want to cycle into a single .txt file, and when changing level the game reads the first line, then the second, and so on without creating several files for a single map each. Is it possible? Thanks! :)
frag.machine
Posts: 2121
Joined: Sat Nov 25, 2006 1:49 pm

Re: Map cycle with FRIK_FILE?

Post by frag.machine »

Not sure if I got correctly what you want when you say " without creating several files for a single map each"... But assuming you have the following .txt:

Code: Select all

e1m8
e1m7
e1m6
e1m5
e1m4
e1m6
e1m2
e1m1
The following algorithm should cycle thru all the maps in the same order of the list and back to the first when the file ends:

Code: Select all

// pseudocode
// open file
// while not in the end of file 
// {
//   read line 
//   if first line read
//   {
//     save it to a var (say, "firstMap")
//   }
//   compares with world mapname
//   if equals 
//   {
//     if not the end of file then
//     {
//       reads another line
//     }
//     else
//     {
//       uses value from "firstMap" var
//     }
//     closes file (always a good practice!)
//     changes level to new map
//     exit while loop
//   }
//}
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
Orion
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Re: Map cycle with FRIK_FILE?

Post by Orion »

I'm getting invalid temp-string offset when opening the file :?

EDIT: This is the code:

Code: Select all

string(string old) CycleMap =
{
	local float o;
	local string line, firstmap, result;
	
	result = "start";	// go to start map if it fails
	
	o = fopen("mapcycle.txt", FILE_READ);
	if (o != -1)
	{
		line = fgets(o);
		while (line != string_null)
		{
			firstmap = line;
			if (firstmap == old)
			{
				if (line != string_null)
					line = fgets(o);
				else
					line = firstmap;
			}
			else
				line = firstmap;
			
			result = line;
			line = string_null;
		}
	}
	
	fclose(o);
	return result;
};
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Map cycle with FRIK_FILE?

Post by Cobalt »

Try strzoning the string data each time you grab it

Code: Select all


line = strzone (fgets(o));
Orion
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Re: Map cycle with FRIK_FILE?

Post by Orion »

Worked, but it keeps cycling between two maps. I think it should memorize the first line, erase it and fputs() into the end of the file.
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Map cycle with FRIK_FILE?

Post by Cobalt »

.string mapname I believe is the current map you have loaded up, so I would say, grab each string from the file until it matches one, then the next string read is the one you want to load nextlevel to. Probably best to strzone everytime you read a string from the file. If you have (8) maps in a rotation, mark the first line in the file with that number. Ftos() > strzone that number and count each string as its read. If it reached 8 you know you are on the last map in the rotation, so you could either mark the end string with another character so that if it reads that character, start over with your count set back to the first position.

This post also has a good example of using Frikfile:

http://forums.inside3d.com/viewtopic.ph ... rik#p44306
Cobalt
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA
Contact:

Re: Map cycle with FRIK_FILE?

Post by Cobalt »

Curious if you got this working? I am gonna try the code myself shortly.
Post Reply