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

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.

主站蜘蛛池模板: 大兴区| 莱州市| 邢台市| 张家川| 四川省| 泸州市| 宜阳县| 库车县| 咸宁市| 丹阳市| 大港区| 于田县| 威海市| 泰兴市| 靖安县| 浪卡子县| 古浪县| 乐安县| 文登市| 六枝特区| 启东市| 南充市| 喀喇| 建昌县| 河源市| 邛崃市| 饶阳县| 龙南县| 开江县| 都江堰市| 承德市| 鄂托克前旗| 临沭县| 务川| 五常市| 舟山市| 常熟市| 永靖县| 兴海县| 中山市| 清流县|