Basic Scripting Tutorial

Post your tutorials here.

Basic Scripting Tutorial

Postby ThatDudeIt » Sun Mar 10, 2019 12:58 pm

What will you learn from this post:
- What does the e.other and e.this mean
- How to liquify objects
- How to change the position of an object (Teleporters)
- How to change the color of an object

The only reason I'm making this post is because I have nothing to upload. So yeah, umm.

TUTORIAL #1:
The basics of e.other and e.this

This is the most important thing to remember if you want to learn how to script.
(Keep in mind I might get some things wrong)
So, what does e.other and e.this mean?

"e" stands for entity (I think)
the ".' between "e" and "other/this" is there to make the script work :/
"other" means we want the script to do something to the OTHER entity.
and "this" means we want the script to do something to the object that has the script "e.this" (because you know, THIS object)

But e.other and e.this itself will not do anything.
You need to add at the end "." and then after the dot, your script.

TUTORIAL #2:
Liquify objects

This is where e.other or e.this comes in.
But first some more info.

- #1
You must decide either you want the object to get liqufied by another object, or by itself.

For now let's say we want it by another object.

- #2
You must decide how you want your object to get liquifed

Let's say you want an object to get liqufied by COLLIDING with another object.

1 - Click on the object you want to have the script with right mouse
2 - Go to Script menu
3 - Find "onCollide ="

onCollide will make the script work by COLLIDING (duh)

Now to the scripting.

The script we will be using is called

e.other.liquify

"e" is entity
"other" is the OTHER entity (that we want to liquify)
and "liquify" is the action we want to do with the script

And the script goes to onCollide in brackets.

Then we click enter and it's done!

:arrow: !!! REMEMBER TO GLUE THE OBJECT THAT WILL LIQUIFY OTHER OBJECTS !!!

Now make another object that is not glued and start the scene.

If you did everything correctly, the object after colliding is now liquifed (turned into water)!

It will look like this:

(e)=>{
e.other.liquify
}

TUTORIAL #3:
Changing the postion of an object

This is commonly used for Algicosathlons and Marble Races (which is not a bad thing!)
But it's also used for Teleporters

The script is called

e.other.pos

in onCollide

"e" = entity
"other" = OTHER object
"pos" = position (action)

But e.other.pos is not a finished script.
We need to add where the object is supposed to go.

So we want the script to look like this:

e.other.pos = [x,y]

"=" stands for what we want the e.other.pos to mean
"[x,y]" stands for the postion (mainly "x" and "y")

x and y will not work just so you know :)

Now to find what numbers does the position that you want the object to go have, you must go to Script menu!
Oh yea, you must make an object in the place that you want to find the position to make it work :/
There you should find "pos ="
After the "=" it shows the position.

For example it would look like this: pos = [-1.9093775, 2.5915225]

So now that you know your position, you can make your script!

It will look like this:

e.other.pos = [-1.9093775, 2.5915225]

"e" = entity
"other" = OTHER object (the object that will be teleported to the position
"pos" position (action)
"=" what we want the script to mean
and "[-1.9093775, 2.5915225]" is the position the object will be teleported to

!!! GLUE THE TELEPORTER !!!

If you did everything correctly, the object after colliding with the teleporter should be in the position you set to!

TUTORIAL #4:
Changing the color of an object

This script is in onCollide just so you know.

There are 2 ways of making this script. The easy one and the hard one.

We obviously want to do the easy one.

The script will look like this:

e.other.color

You know what "e" and "other" mean at this point...
"color" means what we want the color of the OTHER entity to be.

Just like the teleporter, e.other.color is not a finished script.

The easy script will look like this:

e.other.color = e.this.color

This script means we want the other entity's color to be just like the color of the object that will change the color.

If the object that will change the color is Blue for example.
The other object will also turn Blue after colliding with the object.

!!! AND GLUE THE OBJECT THAT WE WANT TO CHANGE COLOR !!!

Now the hard one:

e.other.color = [0.0, 0.0, 1.0, 1.0]
OR
e.other.colorHSVA = [240.0, 1.0, 1.0, 1.0]

(The numbers will make the object blue after colliding)

Now the reason why this is harder is because it takes more time to do it.
(And because of another thing that I will not say because it's hard to explain)

Of course you can still do the hard one if you prefer.

I hope I helped in some way! :)
-ThatDudeIt
ThatDudeIt
 
Posts: 5
Joined: Fri Feb 15, 2019 9:48 pm

Re: Basic Scripting Tutorial

Postby FRA32 » Mon Mar 11, 2019 10:19 pm

"e" actually stands for "Event", since onCollide, onLaserHit, postStep, etc. are all so called events (code that is executed when something happens). The dots '.' are used to look "into" something. Imagine "e" like a tree. "e" is the root of the data tree, "other", "this", "laser" etc. are the main branches of this tree, and "pos", "color", "density", "onCollide" etc. are the leaves of the tree. Only the "leaves" of the data tree can be changed, but you can new "leaves" too by using ":=" instead of "=".
FRA32
 
Posts: 227
Joined: Wed Dec 03, 2014 9:51 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 2 guests

cron