Set Level CVars Example

From Blue Mars Developer Guidebook

Jump to: navigation, search
There are security restrictions on this article

Contents

Overview

City Developers can configure Console variables settings to achieve aesthetic goals, performance goals, etc. A convenient way to do this is to automatically set the desired CVar settings upon loading the city/level. The example in the first section describes how to create a simple entity script for this purpose, and how to add it to your level. For the developers who aren't interested in creating a script, the second section describes how to use an ARAvatarTrigger's Properties to get similar results.

Upon unloading the level, these CVars are reset so the settings do not carry over to another level.


Set CVars via simple entity script

Two files are needed to create the entity script:

  • an .ent file to register the entity
  • a .lua file which contains the script

Either create them in a text editor as described below or grab the sample File:LevelCVars.zip (extract the .zip file in your Common directory and adjust the .ent path as described below).


.ent file

1. Register the entity script by creating a text file containing the code below. Save it as SetMyLevelCVars.ent in your Entity directory (the sample is saved in Levels/AR/Common/Entities). Change this path to reflect your company code and the path to your Lua script.

<Entity
 Name="SetMyLevelCVars" 
 Script="Levels/AR/Common/Scripts/Entities/SetMyLevelCVars.lua"
/>


.lua file

2. Create another text file containing the following code. Save it as SetMyLevelCVars.lua in the directory specified in the .ent's path above (under your company Scripts directory).

SetMyLevelCVars =
{
  Properties = 
  {
    fSetValue = 0,
  },

  Editor=
  {
    Icon="AR_Default.bmp",
    ShowBounds=0,
  },
}

function SetMyLevelCVars:SetSomeCVars()   
  System.Log("SetMyLevelCVars:SetSomeCVars");
  System.SetCVar("r_MotionBlur",self.Properties.fSetValue); --use self.Properties.fSetValue to test different values set in the editor
  System.SetCVar("r_DisplayInfo",0); --or set the value here
end

function SetMyLevelCVars:OnInit()
  System.Log("SetMyLevelCVars:OnInit");
  if (System.IsEditor()) then
    self:SetSomeCVars();
  else
     MMO:RegisterStartCallback(function()
                                 self:SetSomeCVars();
                               end)
  end
end


--for testing in the editor
function SetMyLevelCVars:OnReset()   
  self:OnInit();
end

function SetMyLevelCVars:OnPropertyChange()   
  self:OnReset();
end

See System.SetCVar, and entering a level for more details on these functions. The sample script sets two CVars. The script's SetValue Property is used for the r_MotionBlur value to illustrate using entity Properties (you can change this value in the Editor), and the r_DisplayInfo is set in the script to 0. Select the entity and hit "Reload Script" in the RollupBar after making changes to the script.

Place in level

3. Re-launch the City Editor, find your SetMyLevelCVars entity in the RollupBar>Entity Browser, under your company code.

4. Drag this entity into your level.

That's it! The SetSomeCVars function will be called upon loading the level and the specified CVars will be set.


Set CVars via ARAvatarTrigger

Alternatively, an ARAvatarTrigger can be set at the level's main SpawnPoint and used to execute a ScriptCommand when the avatar enters it. To set the r_MotionBlur CVar as in the previous example, simply enter the SetCVar call in the ScriptCommand as pictured below.

System.SetCVar("r_MotionBlur",0);

Check the OnlyLocalAvatar and TriggerOnce Properties so the trigger will only respond to the player's avatar once upon entering the level.

Using an ARAvatarTrigger's ScriptCommand Property


Multiple CVars can be set by listing multiple calls to SetCVar in the ScriptCommand Property, e.g.:

System.SetCVar("r_MotionBlur",0);System.SetCVar("r_displayInfo",0);
Problems with this wiki page? Contact us either by: Support Email or Support Ticket System

Blue Mars Guidebook Privacy Policy
Blue Mars Guidebook Community Guidelines

Personal tools