Please login or register.

Login with username, password and session length
Advanced search  

News:

Forum rules - please read before posting, it can save you a lot of time.

Author Topic: Problems writing to file  (Read 2047 times)

0 Members and 1 Guest are viewing this topic.

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently working on Colors on Canvas
    • View Profile
    • Dev Blog
Problems writing to file
« 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!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5677
    • View Profile
    • Dead:Code Site
Re: Problems writing to file
« Reply #1 on: August 26, 2018, 04:27:07 PM »

If you want to append stuff to an existing file, you should use OpenAsText(3).
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

mihaipuiucernea

  • Lurker
  • *
  • Karma: 1
  • Offline Offline
  • Gender: Male
  • Posts: 29
  • Currently working on Colors on Canvas
    • View Profile
    • Dev Blog
Re: Problems writing to file
« Reply #2 on: August 26, 2018, 04:29:08 PM »

Thank you!

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

Page created in 0.194 seconds with 22 queries.