File exists?
by Xavier "eXoDuS" Amado · in Torque Game Engine · 06/04/2002 (9:18 am) · 11 replies
How can you check if a file exists?
So before running any load commands on a file check if it really exists.
So before running any load commands on a file check if it really exists.
About the author
#2
Damn, i looked in the TGE Script docos before posting but didnt saw it :\
06/04/2002 (9:26 am)
Woah, quick answer.. 2 minutes :DDamn, i looked in the TGE Script docos before posting but didnt saw it :\
#3
I have been down that road many times in the past, and
more than likely will revist that path in the near future.
-Ron
06/04/2002 (9:40 am)
no worries big fellah :)I have been down that road many times in the past, and
more than likely will revist that path in the near future.
-Ron
#5
no matter what i do (even if i know the file exists) it always returns false. heres what im doing
%this.player = %player;
%this.setControlObject(%player);
echo("Setting up player data....");
%this.player.stats = new scriptObject();
%playername = strToPlayerName(%this.player.getShapeName());
if (IsFile("./Players/"@%playername@"/stats.sav"))
{
echo("player exists loading data....");
LoadPlayerData(%this, "stats");
}
else
{
echo("new player created....");
%this.player.stats.con = $DefaultStats::Con;
%this.player.stats.str = $DefaultStats::Str;
%this.player.stats.int = $DefaultStats::Int;
%this.player.stats.wis = $DefaultStats::Wis;
%this.player.stats.agi = $DefaultStats::Agi;
%this.player.stats.lvl = $DefaultStats::Lvl;
%this.player.stats.kingdom = $DefaultStats::Kingdom;
%this.player.stats.tribe = $DefaultStats::Tribe;
}
i dont know if the loading function works because IsFile() is always returning false. help?
03/05/2005 (3:47 am)
Im having a problem with thisno matter what i do (even if i know the file exists) it always returns false. heres what im doing
%this.player = %player;
%this.setControlObject(%player);
echo("Setting up player data....");
%this.player.stats = new scriptObject();
%playername = strToPlayerName(%this.player.getShapeName());
if (IsFile("./Players/"@%playername@"/stats.sav"))
{
echo("player exists loading data....");
LoadPlayerData(%this, "stats");
}
else
{
echo("new player created....");
%this.player.stats.con = $DefaultStats::Con;
%this.player.stats.str = $DefaultStats::Str;
%this.player.stats.int = $DefaultStats::Int;
%this.player.stats.wis = $DefaultStats::Wis;
%this.player.stats.agi = $DefaultStats::Agi;
%this.player.stats.lvl = $DefaultStats::Lvl;
%this.player.stats.kingdom = $DefaultStats::Kingdom;
%this.player.stats.tribe = $DefaultStats::Tribe;
}
i dont know if the loading function works because IsFile() is always returning false. help?
#6
03/05/2005 (3:51 am)
Try to use echo("./Players/"@%playername@"/stats.sav") to see if the correct path is used. Just to be sure.
#7
any other suggestions?
03/05/2005 (3:54 am)
Yes it is the correct path im using "./Players/EVilleDoEr/stats.sav"any other suggestions?
#8
03/05/2005 (3:56 am)
Just as a note....when i wrote the file i used the same path but it saved it in the games root directory. Is that where its trying to read from?
#9
Double and triple check your paths and filename. This is most likely the cause. Second thing to try is using the cs extension instead of .sav
03/05/2005 (11:14 am)
It is trying to search where you are telling it to search. If it is writing the file someplace else, then it will not be able to find it.Double and triple check your paths and filename. This is most likely the cause. Second thing to try is using the cs extension instead of .sav
#10
Tried using "~/Players/....." Instead of "./Players/...." ?
03/05/2005 (11:25 am)
It looks like he saves and loads player stats, so no need to rename it to .cs i guess. Tried using "~/Players/....." Instead of "./Players/...." ?
#11
If I try to use $loadgame_base to tell it to save, it creates a directory called "~"! If I try to use $savegame_base to find the file, it fails!
02/13/2006 (12:54 pm)
There has to be a bug here. I had the exact same problem, and the way I solved it cannot be the preferred way of doing it.$savegame_base = "./T2D/data/savegames/game_"; // where save
$loadgame_base = "~/data/savegames/game_"; // where we load from
function loadGameData(%gameID){
%filename = $loadgame_base @ %gameID @ ".cs";
echo("Checking " @ %filename);
if(IsFile(%filename) == true){
echo("Loading game " @ %filename);
exec(%filename);
} else {
echo("Creating game " @ %filename);
createGameData();
gameData.mapdot_current = 1;
}
setupT2DScene("map",$mapbase @ "worldmap_1.map");
}
function GameDataObj::saveGameData(%this,%gameID){
%filename = $savegame_base @ %gameID @ ".cs";
%this.save(%filename);
return true;
}If I try to use $loadgame_base to tell it to save, it creates a directory called "~"! If I try to use $savegame_base to find the file, it fails!
Associate Ron Yacketta