WEBVTT

00:00:03.400 --> 00:00:05.211
Let's give a gem some new behaviour,

00:00:05.211 --> 00:00:06.488
written in TypeScript.

00:00:06.488 --> 00:00:08.480
Open the GameStudio menu.

00:00:09.033 --> 00:00:10.583
Choose New Component.

00:00:10.670 --> 00:00:13.277
A component is data you attach to objects.

00:00:13.833 --> 00:00:15.105
Name it Bob.

00:00:17.367 --> 00:00:18.458
Click Create.

00:00:18.458 --> 00:00:23.636
GameStudio writes src/components/bob.ts from a template,

00:00:23.636 --> 00:00:25.930
and opens it in your code editor.

00:00:26.500 --> 00:00:28.909
Swap the example field for two of your own:

00:00:28.996 --> 00:00:31.162
how far it bobs, and how fast.

00:00:31.167 --> 00:00:32.648
Then save the file.

00:00:33.200 --> 00:00:34.547
Bob holds the data.

00:00:34.547 --> 00:00:36.376
The behaviour goes in a system.

00:00:36.462 --> 00:00:38.605
Open the GameStudio menu again,

00:00:39.167 --> 00:00:40.810
and choose New System.

00:00:42.167 --> 00:00:43.590
Name it Bob as well.

00:00:43.595 --> 00:00:45.854
GameStudio calls it Bob System.

00:00:46.433 --> 00:00:48.854
Query picks the objects the system works on.

00:00:48.894 --> 00:00:50.212
Open the list,

00:00:50.767 --> 00:00:51.957
and choose Bob:

00:00:52.044 --> 00:00:54.361
every object with a Bob component.

00:00:54.933 --> 00:00:55.920
Click Create.

00:00:55.920 --> 00:00:57.986
The new system's update runs every frame,

00:00:57.986 --> 00:00:59.734
for each of those objects.

00:01:00.300 --> 00:01:02.442
Swap the example for a few lines.

00:01:02.529 --> 00:01:04.352
wave gives the height at any moment,

00:01:04.352 --> 00:01:07.632
and each frame the object moves by how much the wave changed.

00:01:07.719 --> 00:01:08.723
Save it.

00:01:09.700 --> 00:01:12.179
Back in Blender, click a gem to select it.

00:01:12.733 --> 00:01:15.073
In the Properties, click Add Component.

00:01:16.067 --> 00:01:18.180
Bob is in the list now, under Gameplay.

00:01:18.180 --> 00:01:19.196
Choose it.

00:01:19.767 --> 00:01:20.702
Scroll down.

00:01:20.707 --> 00:01:22.182
There's Bob, with the description

00:01:22.182 --> 00:01:24.336
from its file, and your two fields.

00:01:24.900 --> 00:01:26.822
Set its Height to half a metre.

00:01:27.467 --> 00:01:28.971
Press F5 to play.

00:01:30.200 --> 00:01:32.029
Click Play on the title screen.

00:01:33.567 --> 00:01:35.965
And the gem bobs up and down.

00:01:36.052 --> 00:01:38.612
Change the system and save it while the game runs:

00:01:38.617 --> 00:01:41.805
it hot-reloads, and you see the change right away.

00:01:42.367 --> 00:01:43.523
That's the pattern:

00:01:43.563 --> 00:01:46.698
a component holds the data, a system holds the behaviour,

00:01:46.698 --> 00:01:48.886
and you tune the fields in Blender.
