Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: problem with opening a text file for reading  (Read 4605 times)

0 Members and 1 Guest are viewing this topic.

pakhpakh64

  • Lurker
  • *
  • Karma: -1
  • Offline Offline
  • Gender: Male
  • Posts: 28
    • View Profile
problem with opening a text file for reading
« on: April 25, 2013, 12:07:12 PM »

hi every body
I have a very irritating problem with File.OpenAsText, I have written an "AfterLoad" event for my game in witch I have a piece of code like this:
Code: WME Script
  1. on "AfterLoad"
  2. {
  3.         SomeWindow.ApplyEvent("Load");
  4. }

and in 'SomeWindow.script' :
Code: WME Script
  1. on "Load"
  2. {
  3.         var ToolStringFILE = new File(Game.SaveDirectory + "\GameDebugModeToolStrings.txt");
  4.         if(ToolStringFILE.OpenAsText(1))
  5.         {
  6.                 // some code here, concerning reading from 'ToolStringFILE'
  7.                 ToolStringFILE.Close();
  8.         }
  9.         else
  10.         {
  11.                 Game.LOG("can't open the file");
  12.         }
  13. }

The first time "AfterLoad" is run every thing work fine, but if I attempt to run the "AfterLoad" a second time, I always end up with "can't open the file" line in wme.log,
I don't know what stops the scripting from opening file.
any help would be much appreciated, please tell me if you need more information.
Logged

2.0

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 217
    • View Profile
Re: problem with opening a text file for reading
« Reply #1 on: April 25, 2013, 03:57:56 PM »

Hmm. Strange issue. Is the file exisits after reading from it?
Try to use something like this for first time:

Code: WME Script
  1. on "Load"
  2. {
  3.         global ToolStringFILE;
  4.         if (ToolStringFILE == null)
  5.              ToolStringFILE = new File(Game.SaveDirectory + "\GameDebugModeToolStrings.txt");
  6.  
  7.         if(ToolStringFILE.OpenAsText(1))
  8.         {
  9.                 // some code here, concerning reading from 'ToolStringFILE'
  10.                 ToolStringFILE.Close();
  11.         }
  12.         else
  13.         {
  14.                 Game.LOG("can't open the file");
  15.         }
  16. }

Also try to check attribute AccessMode before trying to open file. Maybe file already opened.
Logged

dongo

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 29
    • View Profile
Re: problem with opening a text file for reading
« Reply #2 on: April 25, 2013, 04:12:55 PM »

Not ear me this lines

i think that the problem is the "AfterLoad" event.

This event launch when the game start, how you launch the event for second time?? ...or when you launch the game for second time... 

i think that something like this is the problem..

sorry for my bad english

edit: bad response, this problem happen you when you load a save game, no?
« Last Edit: April 25, 2013, 04:48:04 PM by dongo »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: problem with opening a text file for reading
« Reply #3 on: April 25, 2013, 04:52:50 PM »

Is the file guaranteed to exist? Perhaps try adding something like Game.LOG(Game.FileExists(Game.SaveDirectory + "\GameDebugModeToolStrings.txt"));
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

pakhpakh64

  • Lurker
  • *
  • Karma: -1
  • Offline Offline
  • Gender: Male
  • Posts: 28
    • View Profile
Re: problem with opening a text file for reading
« Reply #4 on: April 26, 2013, 05:49:12 AM »

1. the file exist after the first time (though I didn't check it with script like what Mnemonic said, I checked the file directory).
2. I have created sort of a small tool for my game to jump through different situation in scene/puzzles, which is based on loading previously saved games. The first time     I use the tool to load a scene the tool reads the file just fine, but the second time it loads an old version of the file which has been used when creating that save.
3. I pretty much hope it's what 2.0 said, I mean could it be when ToolStringFILE.Close() is executed, the File handle is also destroyed?

btw thanks for the reply.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: problem with opening a text file for reading
« Reply #5 on: April 26, 2013, 06:42:41 AM »

but the second time it loads an old version of the file which has been used when creating that save.
I don't think that's technically possible.

Keep in mind when loading a saved game you're also possibly loading old scripts (the ones that were running at the time you were saving the game). Could that be the problem?
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

pakhpakh64

  • Lurker
  • *
  • Karma: -1
  • Offline Offline
  • Gender: Male
  • Posts: 28
    • View Profile
Re: problem with opening a text file for reading
« Reply #6 on: May 19, 2013, 05:07:01 AM »

yes that was it, thanks a lot Mnemonic.
Logged
 

Page created in 0.054 seconds with 25 queries.