Forum

Map cycle with FRIK_FILE?

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Map cycle with FRIK_FILE?

Postby Orion » Thu Jan 30, 2014 5:00 pm

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! :)
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Re: Map cycle with FRIK_FILE?

Postby frag.machine » Thu Jan 30, 2014 6:03 pm

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)
User avatar
frag.machine
 
Posts: 2069
Joined: Sat Nov 25, 2006 1:49 pm

Re: Map cycle with FRIK_FILE?

Postby Orion » Fri Jan 31, 2014 2:34 am

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;
};
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Re: Map cycle with FRIK_FILE?

Postby Cobalt » Fri Jan 31, 2014 5:46 am

Try strzoning the string data each time you grab it

Code: Select all

line = strzone (fgets(o));
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA

Re: Map cycle with FRIK_FILE?

Postby Orion » Fri Jan 31, 2014 5:25 pm

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.
User avatar
Orion
 
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Re: Map cycle with FRIK_FILE?

Postby Cobalt » Fri Jan 31, 2014 8:06 pm

.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:

viewtopic.php?f=2&t=4852&p=44306&hilit=crazy+frik#p44306
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA

Re: Map cycle with FRIK_FILE?

Postby Cobalt » Mon Jun 29, 2015 3:20 am

Curious if you got this working? I am gonna try the code myself shortly.
User avatar
Cobalt
 
Posts: 445
Joined: Wed Jun 10, 2009 2:58 am
Location: New England, USA


Return to QuakeC Programming

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests