TechOFreak

Episode 46 Functions

Jul 30th, 2021
3,304
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //From my Amnesia Rebirth Tutorial Series
  2. //Episode 46 Config Files
  3. //https://www.youtube.com/playlist?list=PL4KkjlmOwLwwMVqedCNpi6caUxhgyf8Qr
  4. //-----------------------------------------------------------
  5.  
  6. //Config file is typically stored under the appropriate user settings file in the directory Documents\My Games\Amnesia Rebirth\Mods\MOD_NAME
  7.  
  8. //Create a global variable to store the config file
  9. [volatile] cConfigFile@ mpConfig;
  10.  
  11. //Load in the config and save it to @mpConfig
  12. @mpConfig = cLux_GetUserConfig();
  13.  
  14. //Immediately apply any changes made to the games options (Ex. Video, Controls, etc.)
  15. cLux_ApplyUserConfig();
  16.  
  17. //Save any updated or newly created variables not related to the games options.
  18. mpConfig.Save();
  19.  
  20. //Print out a message in the debug output at the bottom left
  21. cLux_AddDebugMessage("Some String");
  22. //message (String)- The meesage you want to print in the debug output.
  23.  
  24. //Changes our decimal number (our float) or our int into a string so that we can print it
  25. cString_ToString(1920);
  26. //floatNumber (float)- the number you wish to convert into a string
  27. //The next 2 values below are optional
  28. //decimalPlaces (int)- the number of decimal places you want to capture
  29. //removeZeros (bool)- should zeros be removed from the end of the number (true or false).
  30.  
  31. //Get the value of an int from the config file
  32. mpConfig.GetInt("Screen", "Width", 0);
  33. //category (String)- the category your variable is in. (Ex. <Screen ...>)
  34. //variable (String)- the variable within the previous category you've specified. (Ex. <Screen Width=...>)
  35. //value (int)- the third variable in a get function is irrelavant. Put any value of the the same type here. (We are getting an int so we should put an int here, like Ex. 0)
  36.  
  37. //Set the value of an int in the config file
  38. mpConfig.SetInt("Screen", "Width", 800);
  39. //category (String)- the category your variable is in. (Ex. <Screen ...>)
  40. //variable (String)- the variable within the previous category you've specified. (Ex. <Screen Width=...>)
  41. //value (int)- the value you want set for this category's variable.
  42.  
  43. //Get the value of a bool from the config file
  44. mpConfig.GetBool("Input", "InvertMouse", true);
  45. //category (String)- the category your variable is in. (Ex. <Input ...>)
  46. //variable (String)- the variable within the previous category you've specified. (Ex. <Screen InvertMouse=...>)
  47. //value (int)- the third variable in a get function is irrelavant. Put any value of the the same type here. (We are getting a bool so we should put a bool here, like true or false)
  48.  
  49. //Set the value of a bool in the config file
  50. mpConfig.SetBool("Input", "InvertMouse", true);
  51. //category (String)- the category your variable is in. (Ex. <Input ...>)
  52. //variable (String)- the variable within the previous category you've specified. (Ex. <Screen InvertMouse=...>)
  53. //value (bool)- the value you want set for this category's variable.
  54.  
  55. //Get the value of a float from the config file
  56. mpConfig.GetFloat("Gameplay", "FOV", 0.0f);
  57. //category (String)- the category your variable is in. (Ex. <Gameplay ...>)
  58. //variable (String)- the variable within the previous category you've specified. (Ex. <Gameplay FOV=...>)
  59. //value (float)- the third variable in a get function is irrelavant. Put any value of the the same type here. (We are getting a float so we should put a float here, like Ex. 0.0f)
  60.  
  61. //Set the value of a float in the config file
  62. mpConfig.SetFloat("Gameplay", "FOV", 99.0f);
  63. //category (String)- the category your variable is in. (Ex. <Gameplay ...>)
  64. //variable (String)- the variable within the previous category you've specified. (Ex. <Gameplay FOV=...>)
  65. //value (float)- the value you want set for this category's variable.
  66.  
  67. //Get the value of a String from the config file
  68. mpConfig.GetString("Main", "Chapter", "")
  69. //category (String)- the category your variable is in. (Ex. <Main ...>)
  70. //variable (String)- the variable within the previous category you've specified. (Ex. <Main Chapter=...>)
  71. //value (String)- the third variable in a get function is irrelavant. Put any value of the the same type here. (We are getting a String so we should put a String here, like Ex. "")
  72.  
  73. //Set the value of a String in the config file
  74. mpConfig.SetString("Main", "Chapter", "Chapter 1");
  75. //category (String)- the category your variable is in. (Ex. <Main ...>)
  76. //variable (String)- the variable within the previous category you've specified. (Ex. <Main Chapter=...>)
  77. //value (String)- the value you want set for this category's variable.
  78.  
  79. /////////////////////////////////////////////////////
  80. //Below is some of the code we wrote in this episode
  81. /////////////////////////////////////////////////////
  82.  
  83. //Basic examples
  84. cLux_AddDebugMessage(cString_ToString(mpConfig.GetInt("Screen", "Width", 0)));
  85. cLux_AddDebugMessage(cString_ToString(mpConfig.GetInt("Screen", "Height", 0)));
  86.  
  87. //If and setint example
  88. if(mpConfig.GetInt("Screen", "Width", 0) == 1920 && mpConfig.GetInt("Screen", "Height", 0) == 1080){
  89.     mpConfig.SetInt("Screen", "Width", 800);
  90.     mpConfig.SetInt("Screen", "Height", 600);
  91. }
  92.  
  93. //If and setbool example
  94. if(!mpConfig.GetBool("Input", "InvertMouse", true)){
  95.     mpConfig.SetBool("Input", "InvertMouse", true);
  96. }
  97.  
  98. //If and setfloat example
  99. if(mpConfig.GetFloat("Gameplay", "FOV", 0.0f) != 99.0f){
  100.     mpConfig.SetFloat("Gameplay", "FOV", 99.0f);
  101. }
  102.  
  103. //Set string example
  104. mpConfig.SetString("Main", "Chapter", "Chapter 1");
  105. mpConfig.Save();
  106.  
  107. void OnGui(float afTimeStep)
  108. {
  109.     ImGui_DoLabel(mpConfig.GetString("Main", "Chapter", ""), ImGui_NrmPos(0.75,0.3,10.0f), ImGui_NrmSize(1.0f,1.0f));
  110. }
  111.  
  112. //If setter example
  113. if(mpConfig.GetString("Main", "Chapter", "") == ""){
  114.     mpConfig.SetString("Main", "Chapter", "New Game");
  115. }
  116.  
  117. //Add to starting room
  118. [volatile] cConfigFile@ mpConfig;
  119.  
  120. @mpConfig = cLux_GetUserConfig();
  121. mpConfig.SetString("Main", "Chapter", "Chapter 1");
  122. mpConfig.Save();
  123.  
RAW Paste Data