Modbox

Modbox

Modbox is a multiplayer game-building sandbox for PC / VR / AR. Currently in private alpha.

Guides    

MBScript the scripting system for the game creation tool Modbox. It was designed instead of using a existing text scripting language (like Lua/Javascript) for a few reasons:

  • To allow for drag and drop editing without a keyboard. 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 code.
  • All changes made to MBScript code are also synced online to other players in real time - and can be edited while playing.
  • Uses the same C# type system that Modbox is built with. The type system is used to show the correct options while editing visual scripting.
  • 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.

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.

Creating Scripts

  • 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 is also used to create Game Managers - which are MBScript assets that are added to the world automatically, and easily accessed by other scripts (like Singletons )

Video Tutorials

Events

  • 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).

A Event line is added for the 'Start' event - printing 'Hello World' to the screen.

A new variable 'SwitchColors' is added, with default value 'True'. Here the Entity's Color will be set a random color every Update if 'SwitchColors' is True

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’
  • After - Run code after a set amount of time.
    There are a few other line types: ‘Local’ for temporary variables, Return to stop running code and return from an event, Repeat to do a loop for a set number of times.

Code can run on multiple events and have conditions setting when it runs:

Here the first event line runs if the Entity's name changed, or if it just started.
The second event line runs when a Collision happens, and if the collision was with a Animated Humanoid

Selecting Variables

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 ‘If’ code line needs a ‘True/False’ value, so after selecting ‘Name’ (which is a Text variable) you still need to return a True/False value, so the ‘Select’ is shown to select an option inside the Name text.

‘Contains’ was selected to check if the name contains ‘Bob’. So if this is True the code inside the ‘If’ line will run.

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:

The code under this “If’ line will now run if the name doesn’t contain ‘Bob’.

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:

Variable Options

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 (like 'Func.Random' for a random number)

Tooltips

Hover over a icon to see a description of the variable and it's value.

You can also hover to see the Value results at any time. Here hovering over Divide shows the value of the Health variable divided by 20

Operations

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:

'Do' can be used to run operations on variables. Here 1 is added to the Number1 variable
The second line shows using the "Tween Lerp" operation to change a color variable over time. This can be run just once to have it slowly turn color every frame.

Lists and Queries

The 'ForEach' line can be used to iterate through lists - like the 'All Entities' list in the world.

Go through all entities in the world and print their position

Go through all Primitive components in the world and print their Material value

You can also do queries on lists (like C#'s LINQ).
Here it prints the Entities that are in a physics body with a mass of greater than 10
Could also keep adding to this, adding a 'OrderBy' to order it by mass.

Editing

  • 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)

Text Editing

  • 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 11 days ago


MBScript


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.