Write/read from config.ini

  • #1, z MateuszSunday, 27. February 2022, 22:07 hodinky 2 years ago
    I want to store audio values in config.ini and read them when game was being launched.
    Unfortunetelly, any topics on  the matter from the wiki seems to be long gone (404).
    Can anyone shine some light how do i write (and retrieve) values from config file?

    Bažant

    59 Posts


  • #2, z afrlmeSaturday, 05. March 2022, 13:49 hodinky 2 years ago
    Sorry, the wiki is back up now. wink

    Here's the link to the config.ini script.

    Imperátor

    7285 Posts

  • #3, z red363Sunday, 06. March 2022, 15:21 hodinky 2 years ago
    Hello!

    According to point 3.
    Can you please tell me where in the script to find the value responsible for changing the language (t_lang)? Those. I absolutely can’t figure out how to make the language change be recorded in config.ini (with volume control and full screen mode, I figured it out - it works)

    According to point 4.
    Where exactly do you need to set the default values? In this script, or somewhere else?

    It would be great to have some example in ved.
    For me personally, this is a Chinese letter. roll

    Fanoušek fóra

    101 Posts

  • #4, z afrlmeSunday, 06. March 2022, 16:57 hodinky 2 years ago
    It's old, but if I remember correcty I included a config.ini script in it - though it might be an even older config.ini script.


    Quick note: I do not write config.ini like the example on the wiki these days. We have shorthand now & there's just more efficient methods available due to various other features & action parts that have been added to the engine since I wrote the config.ini tutorial/example that's available on the wiki - & especially since I created that advanced menu template quite a number of years ago. Having said that, it's still viable.

    Imperátor

    7285 Posts

  • #5, z red363Sunday, 06. March 2022, 23:16 hodinky 2 years ago
    Thanks, I'll try to study an example.

    I understand correctly that in order to set the defaults that will work with the first proposed game (volume, language, etc.), you need to edit the config.ini file at AppData\Local\... (in the same place where you can see messages.log from the editor)? And only then build the game. Is it normal that when I change the settings in the .vis file, the games overwrite the values in the same config.ini (and not in the one located in the folder with the .vis file)?

    Fanoušek fóra

    101 Posts

  • #6, z afrlmeSunday, 06. March 2022, 23:30 hodinky 2 years ago
    Yeah, because that config.ini is just meant as a barebones one that is used to launch the game. I suppose you could also read & write the config.ini located in that folder, but the general idea is that you use steam or whatever to store files located in the localAppDir folder to the cloud, so that if they delete the game the config.ini & save files, etc can be recovered without them having to setup the options again or play the game from the start.

    Imperátor

    7285 Posts

  • #7, z red363Monday, 07. March 2022, 01:06 hodinky 2 years ago
    Understandably.....

    Right now the script writes the language value to config.ini, but it doesn't seem to be able to read this value when the game starts. What could be the problem? What to check?

    for example:

    2:02:32.233:config.ini: Unknown Field: TextLanguage

    2:02:32.404:-- * --
    2:02:32.404:config.ini exists
    2:02:32.404:retrieving settings from config.ini
    2:02:32.404:file is currently linked to Data.vis
    2:02:32.404:window mode is currently set to Windowed
    2:02:32.404:[string "(30,20)"]:50: call to setValue on object Unnamed (eGame,-1) failed
    2:02:32.404:stack traceback:
     [C]: in function 'debugerror'
     [string "function debugfunc(err) debugerror(err) end"]:1: in function 'debugfunc'
     [C]: in method 'setValue'
     [string "(30,20)"]:50: in function 'read_ini'
     [string "(8,11913)"]:1: in main chunk
    2:02:32.404:Failed to run string in Lua:
    2:02:32.404:String content: read_ini()

    Apparently I need to edit something in the script itself. But where and what I can not understand. I am using script from wiki

    A couple more explanations:
    I added read_ini() to the initial actions in the game properties.
    The "cfg_update" condition is always true for me, i.e. the idea is that if the player enters the settings menu, changes something or does not change, write_ini () occurs anyway when exiting this menu.
    It seemed to me so much easier than changing this parameter to true every time after certain changes in the settings

    Fanoušek fóra

    101 Posts

  • #8, z afrlmeMonday, 07. March 2022, 13:14 hodinky 2 years ago
    The idea behind the cfg_update - probably - was so that people could change things, but then optionally cancel it out, but that requires additional steps as you need to read the config.ini again & call the action block that updates the options based on it.

    As for the error it's saying that it's something on line 50 & something about TextLanguage being an unknown field. Did you uncomment it or add that somewhere yourself?

    As for the config.ini example, it's just that it's an example template, it's not plug & play. If you try to use it as it is then it will generate errors as all the conditions & values, etc listed in the config.ini script need to exist somewhere. The issue is most likely that it's trying to query something that doesn't exist.

    As I already mentioned, I don't write config.ini scripts like that anymore as we have shorthand & other ways of querying things, like the if lua result action part Simon added to VS5, which works great in combination with execute a script & other action parts. Also he added the ability to link values to the properties tab belonging to scene objects, which means you can easily toggle which option to show by having the same value linked to each image/animation belonging to the same option.

    Imperátor

    7285 Posts

  • #9, z MateuszTuesday, 08. March 2022, 00:50 hodinky 2 years ago
    Thank you, Lee.

    Bažant

    59 Posts

  • #10, z afrlmeTuesday, 08. March 2022, 01:25 hodinky 2 years ago
    I didn't fix it mate, I was just letting you know that it's back online. I don't remember if you are in our discord or not, so I figured I'd let you know in this thread. smile

    Imperátor

    7285 Posts

  • #11, z red363Tuesday, 08. March 2022, 04:34 hodinky 2 years ago
    Thank you for the answer.

    Of course, I understand that this is an example that needs to be edited, supplemented, etc. depending on your needs.

    Regarding more efficient solutions related to the work of config.ini:
    Do you plan to release in future some kind of reference/training material where this would be demonstrated?

    That would be cool, because I'm sure that most indie developers who have bought a license and plan to publish the game have/will have many questions regarding this not an easy topic. Who chose this engine in the hope that they would not have to learn Lua or any other programming language from scratch to make a finished product.

    p.s. I figured out the change of languages, thanks for the hint.

    And another question in pursuit, what do these kinds of errors mean?:
    "6:57:33.393: Failed to initialize compound file 'Scene004.vs'. Failed to open."
    (because this scene works)

    Fanoušek fóra

    101 Posts