• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML [SOLVED] Reading sections of .ini file 'in order'

E

Ehkber

Guest
Hi! I recently created a little system for visual novel-style cutscenes that works by reading values from an .ini file like a play script. It looks like this:
Code:
[1]
S = Justina
T = Is nine fifty seven. Do we risk turning off the grill?
A1 = Justina
A2 = Dee
A1Flip = true
A1x = 400
A2x = 0
A1i = 0
A2i=0

[2]
S = Dee
T = "If ten bloody years at this job has taught me anything it's that nine fifty seven is the perfect time for some drunk guy to decide he wants a burger.#Peak moron time y'getme. "
A1Flip = false
A2 = Dee
A2x = 550
A2i = 1

[3]
S = Justina
A1Flip = 1
T = I see. I see.
It works pretty well but I have one problem that's impeding my efficiency; it requires every section to be manually numbered.
Every time I write one of these things I either accidentally repeat a number or decide I want to break up a section and have to renumber everything after that point.

I didn't find anything like this in the .ini section of the manual, but can anyone think of a way where I can count through the sections of an ini file in the order they're written in? I'd love if if I could just leave the sections blank and write without having to think about what number 'scene' I was on.

Thanks in advance for any help!
 
E

Ehkber

Guest
Why aren't you just using file_text_* functions, then?
Short answer: Because I can't figure out the first thing about how to devise a way of reading them :v

I was hoping there would be a way of making this improvement without starting my learning from scratch but if that's the best solution I'll start looking into it
 

Binsk

Member
Well, there are always multiple ways to approach the problem. The INI method isn't a bad one.

I suppose you could have a "DUMMY" INI entry where you have a key for every section that you need. Then for the key's value it stores the name of the section.

This way you just read through the dummy keys in order to get the appropriate section name to read from for your text. It would allow you to add/remove pieces and have them out of order since the order would be stored in your dummy section.
 
I

icuurd12b42

Guest
Use json
buffer_load to open the file into a tmp buffer
buffer_read with buffer_string to read the file into a string
json_decode to convert the string into a ds_map based data structure holding the json content
buffer_delete to free the buffer.

keep the ds_map with its content and use ds_map_destroy when done with it

Forget this ini bs man seriously, this aint 1993
 
I

icuurd12b42

Guest
Were ini used in 1993? Given they are slower nowadays.
INI is a windows thing, and they improved its performance on windows 3 or 95 if I remember right, by adding caching so it's faster than straight up text file, still not the best solution for efficiency. Also Yoyo's implementation is NOT the windows version last I tested.

Still, people should stop thinking ini and start thinking json :)
 

YanBG

Member
I plan to use json for save files. Learned ini in 2015 and stopped using it last year.

Right now i have only txt turned to csv files, which i load to grids(thanks to Juju for the script). So that data isn't hardcoded.
 
E

Ehkber

Guest
Forget this ini bs man seriously, this aint 1993
The main reason I was drawn to using inis was that the documentation page had a very clear example of how one would lay them out, and it looked like a really quick and initiative way to get words on a page that were usable for my game but also easy to read back for me, a human. Looking at JSON files, it already looks like they have a few more complications and caveats that make me reluctant to switch over.

However your suggestion use DS_maps did give me an idea for a solution which I just spent the evening spaghetti-ing into existence and seems to be working pretty great!

Basically I realised that if two sections in a ini file have the same name, Game Maker always favours reading the bottom one. Knowing this I told my cutscene object's creation event to copy the ini containing my dialogue to a new file then use a for loop to grab values from last section labelled "" , add them to lists and the delete that section. My click event then reads through those lists backwards until it runs out of items at which point it deletes the new file and the lists.

EDIT: For whatever reason this doesn't work when compiled for HTML5 Blerrr X{

Now to write cutscenes I can just write like this
Code:
[]
S = Dee
T = Yeah, well... somefink like that.

[]
S = Justina
T = Alright, Dee! Is deal! We will count down the second hands together!

[]
T = Is thirty seconds to go!

[]
T = Is twenty second now, Dee!

[]
T = Dee is almost time!
which is... a super fast way of working! So if living in 1993 is the price to pay for that, I'll take it :v

Thanks for everyone's replies on this!
 
Last edited by a moderator:
Not meaning for this comment to be nasty, but you obviously are going to release this in english, and you'll maybe want someone proofreading it. Is this character deliberately speaking in what is referred to as "pidgin english"? From your post it's all correct, but in the code text it's somewhat wrong. If this is intentional, then ignore this :) otherwise these are incorrect:

is thirty seconds to go
Dee is almost time
Alright Dee! is deal
is twenty seconds to go

This is the correct way in english:

it's thirty seconds to go
Dee it's almost time
Alright Dee! it's a deal
it's twenty seconds to go
 
E

Ehkber

Guest
Not meaning for this comment to be nasty, but you obviously are going to release this in english, and you'll maybe want someone proofreading it. Is this character deliberately speaking in what is referred to as "pidgin english"? From your post it's all correct, but in the code text it's somewhat wrong. If this is intentional, then ignore this :)
It IS intentional! The character Justina speaks English as a second language, glad it came across as such :p
 
No worries! I did wonder about that, and wanted to draw attention to it just in case. There's a czech chap who is my neighbour, and that's how he speaks in english. You can get the intent, even though it's not quite structured properly. So, yeah - you have captured that :)
 
Top