kam86
|
 |
Posted on: June 12, 2014, 09:32:24 pm |
|
|
 Joined: Jun 2014
Posts: 5
|
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.
|
|
« Last Edit: June 12, 2014, 09:35:06 pm by kam86 »
|
Logged
|
|
|
|
time-killer-games
|
 |
Reply #1 Posted on: June 12, 2014, 10:08:30 pm |
|
|
"Guest"
|
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.
|
|
« Last Edit: June 12, 2014, 10:15:31 pm by time-killer-games »
|
Logged
|
|
|
|
Goombert
|
 |
Reply #2 Posted on: June 13, 2014, 02:25:59 pm |
|
|
 Location: Cappuccino, CA Joined: Jan 2013
Posts: 2991
|
All I know is they use the native functions on Win32, if GM uses those functions, there should be no reason why numerical keys would not work. All of the functions are implemented here. https://github.com/enigma-dev/enigma-dev/blob/master/ENIGMAsystem/SHELL/Platforms/Win32/WINDOWSregistry.cppCan you provide an example GMK or something as well so that I can test?
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect. 
|
|
|
|
|
Goombert
|
 |
Reply #5 Posted on: June 14, 2014, 11:54:25 am |
|
|
 Location: Cappuccino, CA Joined: Jan 2013
Posts: 2991
|
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.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect. 
|
|
|
|
|
kam86
|
 |
Reply #8 Posted on: June 14, 2014, 01:12:29 pm |
|
|
 Joined: Jun 2014
Posts: 5
|
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.
|
|
|
Logged
|
|
|
|
kam86
|
 |
Reply #9 Posted on: June 14, 2014, 08:35:41 pm |
|
|
 Joined: Jun 2014
Posts: 5
|
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 
|
|
|
Logged
|
|
|
|
Goombert
|
 |
Reply #10 Posted on: June 14, 2014, 08:52:15 pm |
|
|
 Location: Cappuccino, CA Joined: Jan 2013
Posts: 2991
|
The issue had nothing to do with ini functions it was the file/directory name. Change the first line to the following and it works in ENIGMA. ini_open(working_directory + "/test.ini") The following will also work. ini_open("./test.ini") Both of those will work in both ENIGMA and GM, so go ahead and just do that. Apparantly the windows INI functions don't recognize the set working directory. http://stackoverflow.com/questions/22138959/c-getprivateprofilestring-read-ini-file-from-current-directoryhttp://msdn.microsoft.com/en-us/library/windows/desktop/ms724353%28v=vs.85%29.aspxSo GM must be appending it to the functions, I have no plans to fix that. It is more of a bug in Windows than in ENIGMA.
|
|
« Last Edit: June 14, 2014, 09:00:20 pm by Robert B Colton »
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect. 
|
|
|
Darkstar2
|
 |
Reply #11 Posted on: June 14, 2014, 08:57:34 pm |
|
|
 Joined: Jan 2014
Posts: 1238
|
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.
|
|
|
Logged
|
|
|
|
|
Goombert
|
 |
Reply #13 Posted on: June 15, 2014, 10:47:01 am |
|
|
 Location: Cappuccino, CA Joined: Jan 2013
Posts: 2991
|
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.
|
|
|
Logged
|
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect. 
|
|
|
|