[create] tutorial by LadyLexUK

Have something important that other people might find usefull? Well, drop it here and help others!
User avatar
LucidStew
Level 3
Level 3
Posts: 180

[create] tutorial by LadyLexUK

Post#1 » Mon Aug 15, 2016 7:11 pm

moved over from projectspark.com forums

Create an object or character in Kode


There are many ways to use the create tile - here are a few examples of what happens:


Key:
numvar:name (A user defined number variable)
boolean:name (A user defined boolean variable)
objset:name (A user defined object set)
objvar:name (A user defined object)
IWP - In world picker

Recommended code for creating single objects/character
WHEN [Once] DO [create][goblin]
This will create one goblin. This line of Kode will run only once in the entire game.

Recommended code for creating multiple objects
WHEN [duration timer] [1][in frames] DO [create] [goblin]
This will create one goblin for each frame specified. Only does this once. Change number to 5 and you get 5 goblins.

Recommended code for spawning multiple objects
WHEN [duration timer] [5][in frames] DO [objvar:my enemy] =[create] [goblin]
...DO [objset: my enemies] [incremented by] [my enemy]
This will spawn 5 goblins and put them into an object set. This set can then be used to destroy all the enemies in one go, count number of enemies that have been created, apply a universal change to all enemies etc...

Recommended code for spawning on a timer

WHEN [numvar:spawn] [<=] [3]
...WHEN [countdowntimer][10][loop]
.../...WHEN [duration timer] [5][in frames] DO [objvar:my enemy] =[create] [goblin]
.../.../...WHEN DO [numvar:spawn] [incremented by] [1]

This will spawn 5 goblins every 10 seconds 4 times then stop

Other correct and incorrect uses of the create tile

WHEN DO [create][goblin]
This will create 1 goblin every frame continuously (30 goblins a second). Not recommended.

WHEN [Page entered] DO [create][goblin]
This will create one goblin every time the page is entered (by using a switch page tile).

WHEN [A][pressed] DO [create][goblin]
This will create one goblin every time the A button is pressed. May cause processing issues if too many goblins are created.

WHEN [A] DO [create][goblin]
This will create 30 goblins a second as long as the A button is pressed. Not recommended.

WHEN [Interacted] DO [create][goblin]
This will create one goblin every time you interact with this object. (Same issue as above)



WHEN [for each of][1] DO [create] [goblin]
This will create one goblin for each number specified continuously.
Pair this with a counter to create the number you require.

eg.
WHEN [numvar:goblin] [=<] [3]
...WHEN [for each of][1]
.../... DO [create] [goblin]
.../... [numvar:goblin] [incremented by] [1]

This will create 4 goblins


WHEN [countdown timer] [1][in frames] DO [create] [goblin]
This will create 1 goblin every frame continuously (30 goblins a second). Not recommended.

WHEN [duration timer] [1] [in frames] [loop] DO [create] [goblin]
This will create 1 goblin every second. Not recommended.

WHEN [countdown timer] [1] DO [create] [goblin]
This will create 1 goblin every frame continuously (30 goblins a second). Not recommended.

WHEN [duration timer] [1] DO [create] [goblin]
This will create 1 goblin every frame continuously (30 goblins a second). Not recommended.

WHEN [started to] [is dead] DO [create] [me] (in a goblin brain)
This will create a second dead goblin when the other goblin is at the point of death.

WHEN [started to] [is dead] DO [create] [goblin] (in a goblin brain)
This will create a new live goblin at the position the previous goblin was in when its health became 0.


WHEN [started to][global][numvar:goblins] [=] [0] DO [create] [goblin]
In all the goblin brains put this Kode
WHEN [Once] DO [global][numvar:goblins] [incremented by] [1]
WHEN [started to][is dead] DO [global] [numvar:goblins] [decremented by] [1]
This will create 1 goblin every time the number of goblins in the world is 0.

WHEN [started to][global][objset:goblins] [count][=] [0] DO [create] [goblin]
In all the goblin brains put this Kode
WHEN [Once] DO [global][objset:goblins] [incremented by] [me]
WHEN [started to][is dead] DO [global] [objset:goblins] [decremented by] [me]
This will create 1 goblin every time the number of goblins in the world is 0.

WHEN [boolean:creategoblin] DO [create] [goblin]
or
WHEN [boolean:creategoblin][=][true] DO [create] [goblin]
This will create 30 goblins a second when the boolean is set to true. Not recommended
Pair this with a child line that creates only 1 goblin at a time.

eg.

WHEN [boolean:creategoblin][=][true]
...WHEN [Once] DO [create][goblin]
End of line.

Return to “Tutorials and guides”

Who is online

Users browsing this forum: No registered users and 1 guest

cron