Page 1 of 1

Map cycle with FRIK_FILE?

Posted: Thu Jan 30, 2014 5:00 pm
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! :)

Re: Map cycle with FRIK_FILE?

Posted: Thu Jan 30, 2014 6:03 pm
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
//   }
//}

Re: Map cycle with FRIK_FILE?

Posted: Fri Jan 31, 2014 2:34 am
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;
};

Re: Map cycle with FRIK_FILE?

Posted: Fri Jan 31, 2014 5:46 am
by Cobalt
Try strzoning the string data each time you grab it

Code: Select all


line = strzone (fgets(o));

Re: Map cycle with FRIK_FILE?

Posted: Fri Jan 31, 2014 5:25 pm
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.

Re: Map cycle with FRIK_FILE?

Posted: Fri Jan 31, 2014 8:06 pm
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

Re: Map cycle with FRIK_FILE?

Posted: Mon Jun 29, 2015 3:20 am
by Cobalt
Curious if you got this working? I am gonna try the code myself shortly.