kam86
 Joined: Jun 2014
Posts: 5
|
 |
Posted on: June 13, 2014, 02:32:24 AM |
|
|
|
Hello, first time poster here. I've recently switched from Game Maker to ENIGMA, but I'm having some trouble with .ini functions. I'm attempting to access a number stored in an .ini file--here's a sample of my code:
ini_open("file.ini"); global.value=ini_read_real("value","1",0) ini_close()
For some reason, only the default value (0) is retrieved, even though the .ini file looks like this:
[value] 0 = 400 1 = 200
Strangely enough, I seem to be able to write to the .ini file just fine. Can anyone tell me where I'm going wrong, or suggest a work around? Any help is appreciated.
|
|
|
time-killer-games Guest
|
 |
Reply #1 Posted on: June 13, 2014, 03:08:30 AM |
|
|
|
first of all using integers as keys (the second arg) is a very bad practice. It's one thing if you do "key0=blah; key1=blah;" but to have a number by itself as the key is very confusing and is probably the issue.
However I can't mess with ENIGMA atm, you'll need further help from someone else. inis worked just fine for me in the past but it might be broken right now so idk.. Make sure the INI is in the same directory as your gmk/exe otherwise it will be the default value 0 because it might have not been found.
|
|
|
|
|
time-killer-games Guest
|
 |
Reply #3 Posted on: June 13, 2014, 09:09:48 PM |
|
|
So you mean this doesn't work on Linux? You know it may be easier to go lazy (like me) and rely on pre-built Win32 API but if you want to go cross-platform I know someone who made a ini reader and writer on the monkey-x forums who might be able to help if y'all need it. Just let me know. 
|
|
|
Darkstar2
 Joined: Jan 2014
Posts: 1,238
|
 |
Reply #4 Posted on: June 13, 2014, 10:14:01 PM |
|
|
|
Been following this topic and can't help but ask a question, sorry if this might seem slightly O/T, but why do people still rely on INI functions ? There are many different ways to store settings, some beginner some more advanced. The easy method by using your own files and using file text reading commands it's more flexible and opens the door for more advanced stuff eventually.
|
|
|
Goombert
 Joined: Jan 2013
Posts: 2,991
|
 |
Reply #5 Posted on: June 14, 2014, 04:54:25 PM |
|
|
|
Darkstar2, no idea, you're right, using ini is really unnecessary. It's extremely simple to write your own file format, just skip lines that start with '//' for comments and bam you can make a format with descriptions making it easy for end users to edit. It would probably read faster too.
If you need more advanced structure, yaml is the way to go, not ini.
|
|
|
Darkstar2
 Joined: Jan 2014
Posts: 1,238
|
 |
Reply #6 Posted on: June 14, 2014, 05:09:06 PM |
|
|
|
I'd like to write new functions to handle it, sort of like INI but enhanced, faster, simpler. But I don't know how to integrate that into the extensions system.
|
|
|
kam86
 Joined: Jun 2014
Posts: 5
|
 |
Reply #7 Posted on: June 14, 2014, 06:08:22 PM |
|
|
Quote from: time-killer-games on June 13, 2014, 03:08:30 AM first of all using integers as keys (the second arg) is a very bad practice. It's one thing if you do "key0=blah; key1=blah;" but to have a number by itself as the key is very confusing and is probably the issue.
However I can't mess with ENIGMA atm, you'll need further help from someone else. inis worked just fine for me in the past but it might be broken right now so idk.. Make sure the INI is in the same directory as your gmk/exe otherwise it will be the default value 0 because it might have not been found.
I'll try changing things as per your suggestion, but I don't think it's using numbers as keys that's causing the problem. This is a direct port from Game Maker, and I didn't have a problem there. Also, I've set things up this way so I can generate a random number and then use that number to access a random key value. I'm not sure how else I would go about doing this. Perhaps it is a momentary issue with ENIGMA, as I haven't been able to get .ini read functions to work in any other games.
|
|
|
kam86
 Joined: Jun 2014
Posts: 5
|
 |
Reply #8 Posted on: June 14, 2014, 06:12:29 PM |
|
|
Quote from: Robert B Colton on June 14, 2014, 04:54:25 PM Darkstar2, no idea, you're right, using ini is really unnecessary. It's extremely simple to write your own file format, just skip lines that start with '//' for comments and bam you can make a format with descriptions making it easy for end users to edit. It would probably read faster too.
If you need more advanced structure, yaml is the way to go, not ini.
I'm a fairly adept Game Maker user, but I don't have a lot of experience with C++. I chose .ini files because the commands are simple in Game Maker and I needed to read and write to an external file. Can you offer some resources or advice on using yaml files? I really don't care which type of file I'm using, but I'm not familiar with anything but .ini so I could use a bit of help.
|
|
|
kam86
 Joined: Jun 2014
Posts: 5
|
 |
Reply #9 Posted on: June 15, 2014, 01:35:41 AM |
|
|
I was able to reproduce the problem in a test file, so I've uploaded the .gmk file and the .ini file. This file contains a single object which reads an .ini file and displays the value--however, because I still can't get it to read correctly I'm guessing the function isn't working in ENIGMA. Can anyone confirm this, or at least give me an alternate suggestion for how to read and write to an external file? My game is almost finished, other than this one issue. Thanks 
|
|
|
|
|
Darkstar2
 Joined: Jan 2014
Posts: 1,238
|
 |
Reply #11 Posted on: June 15, 2014, 01:57:34 AM |
|
|
I discovered this on my own once when playing with external files,  One thing to note, kam86, I noticed you assigned a sprite to an object in your test. You don't need to do that if you don't need to use the sprite. You can create empty object assigned to nothing, code in them will be executed, so long as they are active and placed in the room. Also, try to get to learn GML it is much simpler than the D&D, you could have replaced the D&D actions with this: (example to drawing at x/y 10,10) draw_text(10, 10, string(global.display));
If you specify no fonts and colour, the default will be a white, 9 point font. In GM you had to declare a font and color, in ENIGMA it sets a default for you.
|
|
|
|
|
Goombert
 Joined: Jan 2013
Posts: 2,991
|
 |
Reply #13 Posted on: June 15, 2014, 03:47:01 PM |
|
|
|
Yeah the difference is because our file text reading functions are part of the c standard library and UNIX compatible, our INI functions only exist for Windows and are platform dependent. It's just Microsoft not following standards, if you have a problem with the inconsistency, take it up with them.
|
|
|
|