Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: mihaipuiucernea on August 26, 2018, 04:15:01 PM

Title: Problems writing to file
Post by: mihaipuiucernea on August 26, 2018, 04:15:01 PM
Hi guys,

I hve a problem.
So I have a text document, and I want to write stuff in it. The idea is to add some new text in the file, under some conditions. This text will be read later.

So in one entity's script I have this code:
Code: [Select]
on "LeftClick"
  {
UserDescFile.OpenAsText(2);
UserDescFile.SetPosition(0);
UserDescFile.WriteText("1");
UserDescFile.Close();
  }

and in another's entity's script, this code:
Code: [Select]
on "LeftClick"
  {
UserDescFile.OpenAsText(2);
UserDescFile.SetPosition(2);
UserDescFile.WriteText("2");
UserDescFile.Close();
  }
My problem is the following: I click on one entity, close the game and check the text file. Sure enough, there's a number at the specified position. Then I open the game, click the other entity, and while there is the new number at the correct position, the old number is deleted. Is this correct behaviour? Is there any way to make all the text remain in the text document, without being deleted after a new left click?

Thanks guys!
Title: Re: Problems writing to file
Post by: Mnemonic on August 26, 2018, 04:27:07 PM
If you want to append stuff to an existing file, you should use OpenAsText(3) (http://docs.dead-code.org/wme/generated/scripting_ref_file.html#OpenAsText).
Title: Re: Problems writing to file
Post by: mihaipuiucernea on August 26, 2018, 04:29:08 PM
Thank you!

Should've checked the help file. You rock  ::rock