linux, allegro, and directories
superstar4410

Ok,

it would appear that linux has a problem with finding files based on a path.

ok heres the part of code that matters

  spell = load_datafile("spell.dat");
  if(!spell)
   {
      file_select("load spell.dat", filename, "dat");
      spell = load_datafile(filename);
      if(!spell){no_dat=0;}else{no_dat=1;}
   }
  }

And when the program runs, the spell.dat is in the same folder as the exe and it dosen't find it and I enter the if(!spell) statement, loading spell from the file_select at runtime it is able load spell.dat

So whats the prob??
???
Thankss

Thomas Fjellstrom

are you in the directory that the program is in when you run it? Are you running it from a console? Or just clicking on the program?

spellcaster

Check the path parameter. That's not a path you pass here. Try "./" instead.
Also use file_select_ex().
Make sure that you pass bothe upper and lower case extension "dat;DAT" just to make sure.

superstar4410

yea i'm in the directory and I'm clicking on it

Evert
Quote:

yea i'm in the directory and I'm clicking on it

Right, so your filemanager is in that directory. Try running the program from the command-line (many things work naturally from a terminal in Linux, so it's probably good to get used to those too).

Amd make absolutely sure the case of the filename is the same in either case - Linux is case sensitive.

superstar4410

Ok I found the direct problem,
maybe its how the path is set

I did some debugging and I found out that
its putting
/home/superstar4410

at the beginning of ever " "
so with spell = load_datafile("spell.dat")
its trying to load /home/superstar4410/spell.dat and thats not the correct path

so how can I fix this

Thanks

[EDIT]:o:o:o:o:o:o

Yea you were right, it works from the konsole fine, but from the folder it tries to add /home/superstar4410 before the path

spellcaster

use allgros functions to get the path of the executable.
Then use that path to prefix your file paths.

superstar4410

not to be lazy but, ::)

could you give me a code example

Evert

The file manager (apparently) starts the program with the working directory set to your home directory. You should probably make the program so that it doesn't care from what directory it is started, as spellcaster suggested.

You could probably do (untested!) chdir(get_filename_path(argv[0])); from main, though that isn't exactly nice.
The other option would be to store the path information in the game config file and read it when the game starts (put configfiles in the directory pointed to by $HOME; use the C function getenv to get it's value).

superstar4410

whats the acutally function name
it dosen't recognize get_filename_path

Steve Terry

I think the function you really need is getcwd(); which returns the current working directory.. argv[0] is the application name and does not always contain the path.

Oooh it's not ANSI/POSIX compliant... but I know it works in Windows/DOS/Linux... what do they exactly mean by that anyway.

Evert

Have a look at the Allegro docs, there's a function like that somewhere that does effectively that. Come to think of it, you shouldn't pass it argv[0], but the result of get_executable_name().

As Steve Terry said though, the result is unreliable. You should really make your game so that it will work from any directory. The config file solution I mentioned above is probably your best bet for now, otherwise just stick with running from a terminal (shouldn't be too hard - you're using make anyway, right ;))

Thread #246330. Printed from Allegro.cc