
Map cycle with FRIK_FILE?
Map cycle with FRIK_FILE?
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! 

-
- Posts: 2126
- Joined: Sat Nov 25, 2006 1:49 pm
Re: Map cycle with FRIK_FILE?
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:
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
e1m8
e1m7
e1m6
e1m5
e1m4
e1m6
e1m2
e1m1
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)

Re: Map cycle with FRIK_FILE?
I'm getting invalid temp-string offset when opening the file :?
EDIT: This is the code:
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?
Try strzoning the string data each time you grab it
Code: Select all
line = strzone (fgets(o));
Re: Map cycle with FRIK_FILE?
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?
.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
This post also has a good example of using Frikfile:
http://forums.inside3d.com/viewtopic.ph ... rik#p44306
Re: Map cycle with FRIK_FILE?
Curious if you got this working? I am gonna try the code myself shortly.