Difference between revisions of "Variables"

Difference between revisions of "Variables"

From BeamNG
(More variable info)
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
  
 
There are some additional options not in the header. If a unit is not defined, the variable will default to a range of -100% to 100% (scaled to fit the min/max values set) in the tuning UI. You can change these by setting "minDis" and "maxDis". Variables with units show the raw values. You can use "step" to change the increments in which the variable changes. "stepDis" works the same, but for the scaled percentage value for unitless variables.
 
There are some additional options not in the header. If a unit is not defined, the variable will default to a range of -100% to 100% (scaled to fit the min/max values set) in the tuning UI. You can change these by setting "minDis" and "maxDis". Variables with units show the raw values. You can use "step" to change the increments in which the variable changes. "stepDis" works the same, but for the scaled percentage value for unitless variables.
 +
 +
{{IconSection|Arguments|Arguments}}
 +
=== Common variable arguments ===
 +
 +
{| class="wikitable"
 +
|-
 +
! Name !! Type !! Optional !! Default Value !! Description
 +
|-
 +
| name|| {{jType|string}} ||  {{Icon|NOk}} || n/a || The name of the variable, used within the jbeam file.
 +
|-
 +
| type|| {{jType|string}} ||  {{Icon|NOk}} || n/a || Type of this variable. Only currently supported type is "range".
 +
|-
 +
| unit|| {{jType|string}} ||  {{Icon|Ok}} || % || Unit displayed in UI for this variable.
 +
|-
 +
| category|| {{jType|string}} ||  {{Icon|Ok}} || alignment || Defines the category this variable falls under in the UI.
 +
|-
 +
| subCategory || {{jType|string}} ||  {{Icon|Ok}} || n/a || Subcategory, displayed within category.
 +
|-
 +
| default|| {{jType|float}} ||  {{Icon|NOk}} || n/a || Default variable value.
 +
|-
 +
| title|| {{jType|string}} ||  {{Icon|Ok}} || n/a || Title of this variable, for displayed in UI.
 +
|-
 +
| description|| {{jType|string}} ||  {{Icon|Ok}} || n/a || Description of variable, shown when mouse is hovered in UI.
 +
|-
 +
|}
 +
 +
=== Range variable arguments ===
 +
 +
{| class="wikitable"
 +
|-
 +
! Name !! Type !! Optional !! Default Value !! Description
 +
|-
 +
| min|| {{jType|float}} ||  {{Icon|NOk}} || n/a || Lowest possible variable value
 +
|-
 +
| max|| {{jType|float}} ||  {{Icon|NOk}} || n/a || Highest possible variable value.
 +
|-
 +
| minDis|| {{jType|float}} ||  {{Icon|Ok}} || -100 || Lowest ''displayed'' value of the variable.
 +
|-
 +
| maxDis|| {{jType|float}} ||  {{Icon|Ok}} || 100 || Highest ''displayed'' value of the variable.
 +
|-
 +
| stepDis || {{jType|float}} ||  {{Icon|Ok}} || 1 || Sets the minimum amount of increment/decrement needed to change the variable value.
 +
|-
 +
|}
 +
  
 
== Usage Cases ==
 
== Usage Cases ==
Line 26: Line 70:
  
 
An interesting possible use for variables would be to position a part, such as cargo on a roof rack, by replacing the x and y [[nodeOffset]] coordinates with variables. You could then position the part in-game anywhere within the predefined range you've set. This concept is used for adjustable track width on all of the cars. The x axis nodeOffset for the wheels is set by the variable.
 
An interesting possible use for variables would be to position a part, such as cargo on a roof rack, by replacing the x and y [[nodeOffset]] coordinates with variables. You could then position the part in-game anywhere within the predefined range you've set. This concept is used for adjustable track width on all of the cars. The x axis nodeOffset for the wheels is set by the variable.
 +
 +
== Expressions ==
 +
You're not limited to just the value of your variable when using it in jbeam. You can also combine your value with expressions. For example:
 +
<source lang="jbeam">
 +
          //camber adjust
 +
          ["rx3r","rh3r"{"beamPrecompression":"$=camber_RR * 1.1"}],
 +
          ["rx3l","rh3l"{"beamPrecompression":"$=camber_RL * 1.1"}],
 +
</source>
 +
 +
You may also use basic math functions such as min, max, cos, etc.

Revision as of 06:48, 13 July 2019

Variables are a new feature introduced in 0.5.0.0. They allow you to change any numeric value in a .jbeam dynamically with the tuning menu in-game.

Example Section

    "variables": [
        ["name", "type", "unit", "category", "default", "min", "max", "title", "description"]
        ["$camber_FR", "range", "", "Alignment", 0.98, 0.95, 1.05, "Front Right Camber", "Percentage of adjustment range"]
        ["$camber_FL", "range", "", "Alignment", 0.98, 0.95, 1.05, "Front Left Camber", "Percentage of adjustment range"]
        ["$trackwidth_F", "range", "m", "Alignment", 0.26, 0.26, 0.29, "Front Track Width", "Widen or narrow the wheel track"]
    ],

Most of the options are pretty self-explanatory. The name of the variable must start with the $ character.

There are some additional options not in the header. If a unit is not defined, the variable will default to a range of -100% to 100% (scaled to fit the min/max values set) in the tuning UI. You can change these by setting "minDis" and "maxDis". Variables with units show the raw values. You can use "step" to change the increments in which the variable changes. "stepDis" works the same, but for the scaled percentage value for unitless variables.


Arguments

Arguments

Common variable arguments

Name Type Optional Default Value Description
name string NOk n/a The name of the variable, used within the jbeam file.
type string NOk n/a Type of this variable. Only currently supported type is "range".
unit string Ok  % Unit displayed in UI for this variable.
category string Ok alignment Defines the category this variable falls under in the UI.
subCategory string Ok n/a Subcategory, displayed within category.
default float NOk n/a Default variable value.
title string Ok n/a Title of this variable, for displayed in UI.
description string Ok n/a Description of variable, shown when mouse is hovered in UI.

Range variable arguments

Name Type Optional Default Value Description
min float NOk n/a Lowest possible variable value
max float NOk n/a Highest possible variable value.
minDis float Ok -100 Lowest displayed value of the variable.
maxDis float Ok 100 Highest displayed value of the variable.
stepDis float Ok 1 Sets the minimum amount of increment/decrement needed to change the variable value.


Usage Cases

Variables can be used for literally any number in a .jbeam, including node position, weight, spring, damp, deform, precompression, or whatever else you can think of. Simply replace the number with the name of the variable (don't forget quotes).

This is an example of using variables to control camber, in this case the upper arm of the Covet's rear suspension. By precompressing the beam, we change the length of it, thus angling the wheel in or out due to the design of the suspension.

          //camber adjust
          ["rx3r","rh3r"{"beamPrecompression":"$camber_RR"}],
          ["rx3l","rh3l"{"beamPrecompression":"$camber_RL"}],

An interesting possible use for variables would be to position a part, such as cargo on a roof rack, by replacing the x and y nodeOffset coordinates with variables. You could then position the part in-game anywhere within the predefined range you've set. This concept is used for adjustable track width on all of the cars. The x axis nodeOffset for the wheels is set by the variable.

Expressions

You're not limited to just the value of your variable when using it in jbeam. You can also combine your value with expressions. For example:

          //camber adjust
          ["rx3r","rh3r"{"beamPrecompression":"$=camber_RR * 1.1"}],
          ["rx3l","rh3l"{"beamPrecompression":"$=camber_RL * 1.1"}],

You may also use basic math functions such as min, max, cos, etc.