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.

DarkBASIC Professional Discussion / [DBP] Text file data not updating when re-read

Author
Message
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 29th Dec 2012 10:44
Hi all, I have been playing with making a scripting system for RPG style dialog.

basicly I use a text file and determine the purpose of a line by its starting character

from inside the program, every time a selection is made, the file is closed and reopened so that any changes to the text file will be added into the mix.

this doesn't happen however, it keeps reading the original version of the txt file until the program is reloaded and then it updates.

here is the code



and here is the text file it is reading


I know your all programmers here but just for the sake of clarity
each character is used as brackets

[ = routine header
[\ = close routine
( = text line
{ = user option followed by name of routine enclosed in [

(project is also attached to post for sake of ease)

can anyone see a reason why the file would not update?

when I alter the txt file, save it and then select a new option which closes and opens the file again, the text has not updated.
Not the end of the world but I would like it to update in real time.

any insight would be greatly appreciated.

kezzla

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Dec 2012 11:37
look at INI files... extremely handy and I can even make a demonstration for you if you like... a video to boot

I use STYX personally but you should be able to find the same functionality in Matrix1Utils...

Let me know if you would like me to do that...

And frankly I gave up on Text file handling the moment I came across them...

Oh I can even demonstrate encrypted/packed INI files or at least Password locked...

Sorry I cannot help with your code above aside from pointing out... that It feels odd to see [word[ instead of [word]

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 29th Dec 2012 11:49
How are you updating the file? That code only reads the string, it doesn't write anything to the file.

Don't forget you can't simply use open to write - see Help file:

Quote: "The file must not exist or the command will fail."
Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 29th Dec 2012 11:54
Quote: "Sorry I cannot help with your code above aside from pointing out... that It feels odd to see [word[ instead of [word]"


yeah that has to do with the token command. I started off with brackets and character finding and isolating and string splitting. a whole lot of hassle and then found the token commands and just adjusted what I had to fit. It is loads easier for the same result.

I think I will changed them to something more symmetrical, I do find that by default I want to close the bracket.

from what I understand an ini file is a txt file with a different file extension. That will make little difference to my updating issue.

the strange part is that the file is being closed and then reopened so it should load the re-saved version.

Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 29th Dec 2012 11:57
Quote: "How are you updating the file? That code only reads the string, it doesn't write anything to the file."


I am updating it from inside the text file. sorry I should have mentioned that.

So i have the program window open, and change the text in the text file and then save the text file.

inside the program, when the screen routine is called, it closes and opens the file in an attempt to read the updated data.

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Dec 2012 12:14 Edited at: 29th Dec 2012 12:15
With an INI file you would have sections almost as you have above...

Only that you can PUSH section Sub-Sections into place...

[Section]
SubSectionA=Value
SubSectionB=Value
SubSectionC=value

The values can be anything... even the Section parts and SubSection headings can be any value you wish so that you can access them easily later...

But going on your last post, the problem is that you have stored the file in memory, DBP grabs a copy of the file into memory [As far as I know] with the EXE, this is why it cannot load in the same file, ensure you are not using the MEDIA option... this might fix the issue, alternatively you could adopt the INI method and dynamically add sections within your program... [You simply add the same section to modify the same text... of course problematic if you are intending to paste huge amounts of text... GET CLIPBOARD$
no? >.<]

Hope you resolve this... but yeah you must always close a file once you have read from it and store that data in a string for later use...

Also always do a



And then you can tokenise the grabbed strings Should be more efficient...

The same rule of opening and closing a file exists with INIs too

I seldom use the code block style above, I am even moving into scripting something I never imagined I would ever get round to... Hope this helps...

EDIT

Fixed Code commenting

Kezzla
17
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 29th Dec 2012 12:42
Quote: "But going on your last post, the problem is that you have stored the file in memory, DBP grabs a copy of the file into memory [As far as I know] with the EXE, this is why it cannot load in the same file, ensure you are not using the MEDIA option... this might fix the issue"


Good work MR V! that fixed it.

I changed the project type from media to exe and the text file cracked it when i tried to save. ah-ha, reshuffled my close file command and now it works.

Quote: "you could adopt the INI method and dynamically add sections within your program... "

The reason for this project is so that I can write conversations in text files and load them with a project. I dont need to add them from inside the program. I wanted it to update in realtime so I could run the conversation in game mode as I was writing it.
the programs sole purpose is to read what I have written in the text file and display it as a conversation with reply options. The only difference between an ini and a text for my purposes is the file extension.

anyway appreciate your help mate, Thankyou.

kezzla

MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 29th Dec 2012 12:46
Anytime buddy

Login to post a reply

Server time is: 2026-07-08 01:56:57
Your offset time is: 2026-07-08 01:56:57