Variables Methods
v4.0
Each GameItemObject has a List<ItemObjectVariable> which contains all the variables, and the current values.
// GameItemObject.cs
public List<ItemObjectVariable> variables
// Returns the ItemObjectVariable with the variableName provided
public ItemObjectVariable Variable(string variableName)
// Note: The Variable() method will return a value that is cached in a Dictionary
// that is populated at runtime. This is more optimized for values that are called
// often. However, depending on your project, you may wish to cache the
// ItemObjectVariable in another location where it is often accessed, perhaps in
// another class.When the Value changes, if variableAttributes are in use, then the system will automatically check to see if the existing GameItemAttribute needs to be updated. If so, the system will remove all GameItemAttributes of the ObjectType from the list, and add the new one based on the current RangeValue.
SetStatsDirt() will then be called on the GameItemObject, triggering stats to recompute their values.
Methods
Get Value & RangeValue
var durability = gameItemObject.Variable("Durability");
// Get the current value
var durabilityValue = durability.value;
// Get the current RangeValue
var durabilityRangeValue = durability.RangeValue;Example
You can use the value of durability to modify the "price" of a GameItemObject.
Add Value
Use the AddValue() method to add value to the Variable. Add a negative value to subtract. The final Value will be clamped between Min and Max, and RangeValue will be updated.
Returns the RangeValue of the Variable.
Set Value
Use the SetValue() method to set the value to a specific amount. Add a negative value to subtract. The final Value will be clamped between Min and Max, and RangeValue will be updated.
Returns the RangeValue of the Variable.
Set to a specific RangeValue
RangeValueRangeValue is always between 0f and 1f, between the Min and Max values and modified by the curve, if in use. Rather than setting the specific Value, you can opt to set a RangeValue, and the Value will be computed based on that.
Returns the Value of the Variable.
Last updated
Was this helpful?