Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Problem with OpenToWrite

Author
Message
nickydemon
4
Years of Service
User Offline
Joined: 19th May 2015
Location:
Posted: 4th Dec 2018 11:30
I am creating a map editor and trying to open a file to write down the map data but my folder doesn't show any file after I closed my application. I read the documentation of "OpenToWrite" and it describes :
->Opens a file stored on the local filesystem for writing into the specified ID. and
->If the file does not exist it will be created

In my understanding, the command will create a file if the file doesn't exist but it didn't work for me. Below is the code.
By the way I coded in C++.


I was wondering if I put the code in the wrong way, or maybe just the folder path problem?
smallg
Valued Member
13
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 4th Dec 2018 16:23
where are you looking for the file? on windows it's in hidden folder AppData/Local/AGKApps
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
nickydemon
4
Years of Service
User Offline
Joined: 19th May 2015
Location:
Posted: 5th Dec 2018 04:24
Hi smallg, thanks for your reply. The file is inside AppData/Local/AGKApps. Yeah maybe I missed reading some part in the documentation.
Anyway, the file is created but there are no values written inside the text.txt file, just spaces. I am not sure if my codes correct or not.
puzzler2018
User Banned
Posted: 5th Dec 2018 07:26
Im not sure on C++, but you have opened a file handle with 1

agk:penToWrite(1, "test.txt", 0);

But I don't think C++ will know what 1 is,

In Tier 1 we would use

file = OpenToWrite("test.txt")

which will produce a file handle and populate it in the variable file.

So maybe if did it like Tier1

file = agk:penToWrite(1, "test.txt", 0);
and then
agk:penToWrite(file, "test.txt", 0);


Would this work?

MadBit
Valued Member
10
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 5th Dec 2018 13:10
For me it makes no sense to keep a file open for the whole runtime of the program.
Wouldn't it be better to save the file when a key is pressed? Or when closing the program.
Would definitely be clearer for error tracking and also safer against data loss.
Also I can't imagine that the code you show us is somehow startable or compilable.
Since you are trying to call a function outside a function ( line: 16, 17 ).
You can't do that with C/C++. This should result in compiler errors.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
MadBit
Valued Member
10
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 5th Dec 2018 13:39 Edited at: 5th Dec 2018 13:44
The one with the compiler error seems to work after all. I remembered it differently.
Sorry.


EDIT:
And your file exist under: c:\Users\$UserName\AppData\Local\AGKApps\My Company\Template64\ (under Windows)
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)

Login to post a reply

Server time is: 2019-08-19 08:31:05
Your offset time is: 2019-08-19 08:31:05