3.1 KiB
title, tags, mentions
| title | tags | mentions | |||||||
|---|---|---|---|---|---|---|---|---|---|
| Molang |
|
|
Introduction
Pretty much everything evaluates to a number; if something doesn't evaluate to a number, you can use an operator to make it into one. You can basically just think of Molang as one big math equation.
An equation evaluates to true when any number except 0 is returned. When I reference returning, I'm talking about the output of an equation. There is also a return statement, but I don't usually use it, and will therefore not be talking about it.
Accessing Values
There are three main ways to access and use values in Molang (queries, variables and temp variables)
-
Queries are read only values returned by the game. You cannot set these values, only read them. (
query.example_query|q.example_query) -
Variables are read and write values that you can manipulate, these can be set and read through Molang. (
variable.example_variable|v.example_variable)- There are also hard-coded variables which act practically the same way as queries, but can only be used in certain situations.
-
Temp. Variables are practically the same as variables, except they only exist in the current scope. (
temp.example_temp|t.example_temp)- A "scope" can refer to the current
for_eachorloopor just the current expression, if it's not used within either
- A "scope" can refer to the current
Handling values
-
Logical Operators can be used to convert non-numbers into 1s or 0s. These include:
==,!=,<,>,<=,>=.-
Example.) "
q.get_equipped_item_name == 'stick'" Will evaluate to1/truewhen holding a stick -
There is also a second set of Logical Operators which can be used to 'group' values into
and/orstatements, often used in cases where you need multiple things to evaluate totrueor just one out of many.&&represents anandstatement, and||represents anorstatement.- Example.) "
q.is_sneaking && q.is_using_item" Will evaluate to1/truewhen sneaking and using an item - Example.) "
q.is_sneaking || q.is_jumping" // Evaluates to1/truewhen either jumping or sneaking
- Example.) "
-
-
Parentheses,
( ), are also a major help when grouping values or performing math operations.- Example.) "
q.is_sneaking && (q.get_equipped_item_name == "stick" || q.get_equipped_item_name == "diamond")" Will evaluate to1/truewhen sneaking and holding either a stick or a diamond
- Example.) "
-
Conditional Operators can be used as
if/elsestatements.- A binary conditional operator refers to just using
?. When this is used, it'll output your value or0depending on whether the given input value istrue.- Example.) "
q.is_sneaking ? 5" Will output a5when sneaking, otherwise returning a0
- Example.) "
- A trinary conditional operator refers to using
?and:. When this is used, it'll output one of the two given values depending on whether your given input value istrue.- Example.) "
q.is_sneaking ? 10 : 3" Will output a10when sneaking, otherwise returning a3
- Example.) "
- A binary conditional operator refers to just using