Skip to content

Programming Mechanic

OutCraft edited this page Jan 22, 2023 · 19 revisions

Basics

Here at Create Robotics you can program you robots with our own script language.
Here you can find all commands properly documented and a lot more!

To program a robot, let's say a Code Drone you first need a Code Editor Block.Right click it with a Program Item to get started!

Now we can start to code. Let's say we have a command called testCommand that takes one argument from type ... let's make it simple: number.

robot.testCommand(5);

Easy, right? Don't forget the ; at the end of each command!

Now something a bit harder:
Let's say we have testCommand2 that takes two arguments from type number and one from type item. Arguments are seperated by a ,.
Try it yourself first!

robot.testCommand2(5, 8, minecraft:diamond_block);

What you can do now is add math to number arguments:

robot.testCommand2(5, 2 + 2 * 3, minecraft:diamond_block);

And what is 2 + 2 * 3? Yes, 8!
The math system follows basic algebraic rules (parentheses/brackets before multiplication/division before addition/subtraction)

Wasn't too hard, right?

Supported math equations

Addition: 3 + 3
Subtraction: 3 - 3
Multiplication: 3 * 3
Division: 3 / 3
Power: 3 ^ 3
Square root: sqrt(5)
Sine, Cosine and Tangent: sin(3), cos(3) and tan(3)
And of course parentheses/brackets/however you call them: (1 + 3) * 5 = 20 and not 16

These are all basics you should know! Let's get to something harder.

Variables

Our script language also supports variables!

Let's say you have a variable called myVar. This is how you can you use that variable in your code:

robot.testCommand(${myVar} + 8);

For a list of all predefined variables look

Defining own variables

There are three types of variables: internal, private and public.
Note that when there are default, private and public variable with the same name it will first try to get the internal, if it doesn't exist the private and if that also doesn't exist the public.

  • internal variables are default variables you can't edit or overwrite.
  • private variables are variables private to only the robot executing it.
  • public variables are shared between all robots. Editing one affects all robots using it.

So how do you define your own variable?

private myVar = 8;

That's it! But let's say you want to add 3 to myVar. How would you do that?

private myVar = ${myVar} + 3;

Commands

WIP

Defaults

The mod has some default (predefined) commands, variables etc.
Find all of them here:

Default Commands

WIP

Default Variables

Clone this wiki locally