Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
0 registered members (), 938 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
packed exe : writing to external txt file? #226254
09/08/08 17:38
09/08/08 17:38
Joined: Feb 2007
Posts: 146
UK
robertbruce Offline OP
Member
robertbruce  Offline OP
Member

Joined: Feb 2007
Posts: 146
UK

Hello,


I have created a small project which I would like to write characters to an external txt file.


I can achieve this using a published .cd folder with the following code:


var fHandle;
action player_position {
while(key_p == 0) { wait(1); }
fHandle = file_open_write("data.txt");
file_var_write(fHandle,int(my.x));
file_str_write(fHandle,"\n");
file_var_write(fhandle,int(my.y));
file_str_write(fHandle,"\n");
file_var_write(fHandle,int(my.z));
file_close(fHandle);
}




The project gives the coordinates of the player and writes them to the txt file.




However, when the project is packed as a single .exe this does not work. I have tried using the following
code


var fHandle;
action player_position{
while(key_pg == 0) { wait(1); }
fHandle = file_open_write("data.txt");
file_var_write(fHandle,int(my.x));
file_str_write(fHandle,"\n");
file_var_write(fhandle,int(my.y));
file_str_write(fHandle,"\n");
file_var_write(fHandle,int(my.z));
file_close(fHandle);
}


and received the following error:

invalid pointer in player_position: file_var_write(fHandle,int(my.x))


What I would like to have is a single .exe gamestudio project with the ability to write to a txt file which is in the same
folder as the exe.

eg;

myproject.exe
data.txt


I've searched through the posts regarding read commands and txt files cannot find anything as yet.

Would appreciate any help.

Thanks,

Rob

Re: packed exe : writing to external txt file? [Re: robertbruce] #226446
09/09/08 19:57
09/09/08 19:57
Joined: Feb 2007
Posts: 146
UK
robertbruce Offline OP
Member
robertbruce  Offline OP
Member

Joined: Feb 2007
Posts: 146
UK
sorry, the second code should read


var fHandle;
action player_position{
while(key_pg == 0) { wait(1); }
fHandle = file_open_game("data.txt");
file_var_write(fHandle,int(my.x));
file_str_write(fHandle,"\n");
file_var_write(fhandle,int(my.y));
file_str_write(fHandle,"\n");
file_var_write(fHandle,int(my.z));
file_close(fHandle);
}

which gives the previously stated error message

Rob

Re: packed exe : writing to external txt file? [Re: robertbruce] #226591
09/10/08 13:48
09/10/08 13:48
Joined: Sep 2002
Posts: 1,065
Germany, Jena, Thüringen
3D_Train_Driver Offline
Serious User
3D_Train_Driver  Offline
Serious User

Joined: Sep 2002
Posts: 1,065
Germany, Jena, Thüringen
Hi!
The second one won`t work.
But I guess it`s a pointer thing. Before writing my.x or the like you should assign the my pointer to an entity for example the player.

I suggest:
Code:

string name_writefile[256];
string file_writefile = "data.txt";

entity* the_player;
var player_position;

var_nsave fhandle;

//any other function that created the player
function create_player(){
the_player = ent_create("playermodel.mdl",player_position,null);
}

//now follows your function
action player_position{
while(key_pg == 0){wait(1);}
my = the_player; //!!!!!!!
str_cpy(name_writefile,work_dir); //copy the work_directory in to the filename first
str_cat(name_writefile,file_writefile); //then add the real file name
fhandle = file_open_write(name_writefile);
if(fhandle){ //if the file has been opened for writing
file_var_write(fhandle,int(my.x));file_asc_write(fhandle,10);
file_var_write(fhandle,int(my.y));file_asc_write(fhandle,10);
file_var_write(fhandle,int(my.z));file_asc_write(fhandle,10);
file_close(fhandle);
}
else{ //in case the file couldn`t be created or found
return;
}
}



The thing with the work directory is to be shure that you`re always in the right directory but normally you don`t need to.
But if you used Nacasi to pack your game into it`s going to be difficult. Then you have to write the whole file name including the path. For example ("C:\\folder1\\folder2\\data.txt")
file_asc_write(fhandle,10); is the same like file_str_write(fhandle,"\n");

Hope I could help.

Last edited by 3D_Train_Driver; 09/10/08 13:56.
Re: packed exe : writing to external txt file? [Re: 3D_Train_Driver] #226884
09/11/08 20:38
09/11/08 20:38
Joined: Feb 2007
Posts: 146
UK
robertbruce Offline OP
Member
robertbruce  Offline OP
Member

Joined: Feb 2007
Posts: 146
UK
Thanks for the reply.

I will test the code.

Great website by the way!

Rob


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1