Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: Problem with file object  (Read 2919 times)

0 Members and 1 Guest are viewing this topic.

Ennio

  • Lurker
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 40
    • View Profile
Problem with file object
« on: January 07, 2012, 06:53:08 PM »

I'm trying to code a script that reads/writes some informations on a .txt file.

I need to save these informations in global variables when the game start, and update them dynamically when some trigger happens in game.

So i included a .inc script (mapInfo.inc) in base.inc and created a file object with my txt. (access: reading).

I read the info and load it in const variable.
Everything works! ok!

But when i try to reopen the file object to write (and update the informations when get the trigger) i get a "File not open" error...the syntax is ok, i think the problem is that the file is opened the firts time and never closed (even though i used file.Close)...or something like that

Someone can help me?
Thanks!
Logged

Ennio

  • Lurker
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 40
    • View Profile
Re: Problem with file object
« Reply #1 on: January 07, 2012, 08:20:37 PM »

Ok problem found... seems that with relative path you can only access a file in reading mode, so to write on it...you have to call a constructor with the full path...like
var MyFile = new File ("C:\document\myfile.txt")....

but obviously this cannot works after compiling the project on another machine...how can i solve this problem?
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 file object
« Reply #2 on: January 07, 2012, 09:49:32 PM »

WME doesn't really care whether the path is absolute or relative, but the user needs to have write permissions for the resulting directory. For that reason I recommend using the Game.SaveDirectory property and store your files there. This directory is always writable.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Ennio

  • Lurker
  • *
  • Karma: 2
  • Offline Offline
  • Posts: 40
    • View Profile
Re: Problem with file object
« Reply #3 on: January 09, 2012, 09:01:22 PM »

Great advise, as usual :D
However debug console continues to return the warning about absolute path, but i image that can ignore it, right?
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 file object
« Reply #4 on: January 09, 2012, 09:31:41 PM »

Yes you can.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
 

Page created in 0.068 seconds with 23 queries.