官术网_书友最值得收藏!

Time for action – Creating config variables

  1. To let the game know that our class needs to save config variables, first we need to let it know which file to use.
    class AwesomeActor extends Actor
        placeable
        config(Game);

    This tells the game that our class' config variables will be defined in the Game ini files as opposed to Engine or Input and so on.

  2. Now, let's make a config variable.
    var config int MyConfigInt;

    Config vars can have parentheses to let level designers change them, but they can NOT be put in the default properties block. Doing so will give a compiler error. Instead, we define their default properties in the INI file we specified. Since we used Game, we would put the default in DefaultGame.ini. Let's open that up now.

  3. In DefaultGame.ini we can see a bunch of different sections, starting with a line surrounded by brackets. The inside of these brackets specifies the package and class that the section is defining defaults for, like this:
    [Package.Class]
  4. In our case our package name is AwesomeGame, and the class we need to define is AwesomeActor. At the end of DefaultGame.ini, make a new section surrounded by brackets.
    [AwesomeGame.AwesomeActor]
  5. Right after that we can define any default values we need.
    MyConfigInt=3

    Once we're done, our section should look like this:

    [AwesomeGame.AwesomeActor]
    MyConfigInt=3
  6. Let's see if it works! In AwesomeActor.uc, change PostBeginPlay to log MyConfigInt.
    var config int MyConfigInt;
    
    function PostBeginPlay()
    {
        'log("MyConfigInt:" @ MyConfigInt);
    }
  7. Compile and run, then check the log file.
    [0008.66] ScriptLog: MyConfigInt: 3

Have a go hero – Editable configurable variable?

Knowing what you know about different ways to define default values for variables, what do you think would take precedence: The config file or a value set by the level editor? Try adding a variable that's both configurable and editable and logging the result.

What just happened?

If we look in UDKGame.ini, we can see that the variable has shown up there as well. Remember that the UDK.ini files are built from the Default.ini files, and instead of changing the Default.ini files, the player and the game work with the UDK.ini ones. That way the game always has a fail safe with the Default.ini files. If the player or a setting menu in the game changed MyConfigInt to 5 for example, then the player changed their mind and used a settings menu to reset everything to the default value, we would be able to do that by using the Default.ini value for that variable.

Now that we've learned about the different types of variables and ways to set their values, let's take a look at some common operators we can use on our variables.

主站蜘蛛池模板: 巴南区| 新乡县| 大渡口区| 德惠市| 田阳县| 津市市| 临武县| 彭泽县| 新乡市| 绥棱县| 东丽区| 杂多县| 丹江口市| 泰兴市| 集安市| 冕宁县| 明溪县| 井陉县| 攀枝花市| 华安县| 墨竹工卡县| 渭南市| 铁岭市| 马尔康县| 平乡县| 绍兴市| 平武县| 桦川县| 陆河县| 嘉黎县| 雷山县| 永吉县| 句容市| 阜宁县| 濮阳县| 荔浦县| 安龙县| 贡觉县| 洛南县| 邢台市| 司法|