- To allow designers to create complex gameplay / AI with drag and drop editing (No syntax errors)
- Can be edited with Keyboard+Mouse, in VR \ AR, with Touch on a mobile device, or with a Gamepad.
- Designed from the start to work online. All code runs online automatically so designers never have to think about networking state
- All changes made to MBScript code are also synced online to other players in real time - and can be edited while playing.
- Unlike node based visual scripting (like Blueprints / Playmaker), MBScript can be switched from visual mode to text mode at any time. A integrated VSCode like text editor (Monaco) is included with Modbox.
- Code can be copied and pasted between the node based Wiring system, which uses MBScript
- It's event based - with events being any variable changes or ingame events on any entity in the world - so MBScript code can be easily hooked into by other scripts / mods.
- Uses the C# type system to show the correct options and validate the drag and drop blocks
Here a MBScript asset is created to have the Entity 'Die' on Collision if the collision speed is over the 'Min Speed to Break' number variable. It also Prints the name of the Entity it collided with.
MBScript assets can be created with the Edit Entity Desktop Window or the Edit VR Tool. Each asset creates a new Entity ComponentEntity Component - Entity Components are on Entities and set their behavior and other properties such as physics / how they look. New components can be made in either MBScript or C# programming type. MBScript Assets can be included in Entity PrefabPrefab - Prefabs are entity assets created ingame out of 1 or more other entities. Prefabs can then be shared online / between creations. (There is also Unity's Prefab system used in the ModboxSDK, which is different but same functionality).
MBScript can be edited/run at anytime (Running in edit mode can be useful for creating Editor tools / operations. Editing in play mode is a easy way to test changes.)
- MBScript code runs on Events, which allows for running code based on any event happening on the Entity or in the world (such as a variable changes value, or a world event happens like a player joins).
The 'On' lines add Event Lines to run code on events. You can then add other code line types to set values / do operations:
- Set - Set a variable's value
- Do - Do a method / operation / or event
- If - Run code if a condition is true. Can then add Else lines
- Print - Print a value to the screen, useful for quick testing
- ForEach - Run code on a list. “Do this to everything in this set". Can run ‘ForEach Entity in the world change it’s material to Wood’
- Wait - Wait a set amount of time before running next code
There are a few other line types: ‘Local’ for temporary variables, Return to stop running code and return from an event, For to do a 'for' loop a set number of times, and While to keep looping while a condition is True
Code can run on multiple events and have conditions setting when it runs:
After adding a code line you use the dropdowns to choose a variable or set a value.
After selecting a variable it will show if it still needs the expected type.
The ‘+’ at the end of the line can be used to continue the line with another operation. So because ‘Contains’ returns a True/False, you can then hit the ‘+’ button and select ‘IsFalse’ to invert that return value:
You can keep adding operations like this. Here the ‘Y’ part of the entity’s scale is selected, and set to the same Y value plus a random value:
When selecting a variable in MBScript you select from either:
- Variables created in the Script
- Local variables (added with Local line or as parameters to the Event)
- Components on the Entity and their variables (like it's Name in the Main component, or Mass in the Physics component)
- Variables in the World (like Gravity, or list of all Material Assets)
- Or Functions - that just return a value. Like 'Func.Random.Value' or 'Func.Mathf.Cos('
Hover over a icon to see a description of the variable and it's value.
To change a variable value the Set line can be used to set to a new value (with "Set X to Y"). It can also be useful to do operations directly on the variable:
The 'ForEach' line can be used to iterate through lists - like the 'All Entities' list in the world.
- Code lines can be dragged by moving the drag handle. Multiple lines can be selected and moved at once. Variables and values can also be dragged to copy them.
- Right click can be used to copy and paste MBScript (which just copies it to the Clipboard as text)
- MBScript can be copy and pasted as text.
- At any time you can switch to text mode to edit, with autocomplete for variable names and immediate error updates.
Here is the same script switched to text mode and edited, checking if the Entity has a 'Primitive Component' set on it, and if it does it prints the value of the Entity's Physics Material AssetPhysics Material Asset - Physics Material Asset sets a Entity physics properties - including it's mass, it's Physics Sound Type, and on damage/collision effects :
Updated 2 days ago