Skip to content

Scripting Language Basics

Math0424 edited this page Jun 13, 2023 · 2 revisions

Starting the script

A script can be broken down into 4 basic components

The Header

  • headers contain information about the script

The Objects

  • objects are your subparts on your block

The Functions

  • functions are little bits of code that can help you do things faster

The Actions

  • this is where the meat of the script lies

Below sections will cover each of these in more detail.

The Header

The header of the script contains information for the mod to determine what block to use this script on.

All scripts require these two headers

@BlockID STRING
@Version 1

Optional headers include @Author STRING

An example of a header would be

@Author "Math"
@BlockID "large_halfblock_sentry_turret"
@Version 1

If you are using WeaponCore events you need to use the header

@Weaponcore [gunId]

Simply adding this to the headers will enable the WeaponCore related events, the GunID will normally be 0 unless your block has multiple gun AI's on it

The Objects

Objects are subparts or dummys that have special attributes. You can call methods in the objects to make the do something, they are your primary way to animate blocks.

For specifics on declarations see the script version you wish to develop for

The Functions

Functions are short bits of named code sections that you can call to do work easier Functions are very simple to declare the format is as follows

func KEYWORD() { }

An example of a function would be

func OpenGate() {
     ResetGateFunc()
     panel_01.translate([-1, 0, 0], 20, cubic)
     panel_02.translate([1, 0, 0], 20, cubic)
}

The Actions

Actions are bits of code that are triggered when certain things happen. This can be anything from player proximity, to idle loops.

They may look intimidating but can also be broken down into two parts. The parent and the children. The formatting is simple but I will refer to the outer part as the parent and the inner part as the children.

Actions are by far the most complex syntax wise, the parent format is declared in the following format action KEYWORD(...) { }

Inside the body of the action you define smaller events, the children format is the following. KEYWORD(...) { }

When making a full action the result will look something like this

action KEYWORD(...) {
     KEYWORD(...) { }
     KEYWORD(...) { }
}

(... represents possible input)

To see the full list of Actions please refer to the script version you wish to develop for

Interacting with Objects

As mentioned before in The Objects section objects can be interacted with. When interacting with objects you can break it down into two parts, the object and the calls. Think of a line to ride an amusement park ride. The ride is the object and the people in line are the calls.

Object in this case represents the keyword that you declared An example of moving a subpart would be the following using part01 as Subpart()

func MoveRight() {
    part01.transform([1, 0, 0], 10, Cubic)
}

Much like the line to the amusement park calls can be behind one another. Using the example from above we can also declare

func MoveLeftAndRotate() {
    part01.transform([-1, 0, 0], 10, Cubic).rotate([0, 1, 0], -30.0, 10, Cubic)
}

There are many different calls, each one is specific and has to follow a certain format. To see the full list of object methods please refer to the script version you wish to develop for

Clone this wiki locally