Step 2

When to use "When Created"

Just before the game starts, all the objects are created one after the other. This is when each object will run the "When Created" event block. You have no control over which game objects are created in which order, and it happens so fast that it doesn't really matter -- but they aren't all created at the same time. This is important because objects will break the game if they try to get information about other objects that haven't been created yet.

Here's are a few examples:

Water is created Enemy is created Character is created Boat is created Example 1:

(gif of loading, then 1 water, then 2 enemy, then 3 character, then 4 boat created)

"When Character is created, make sure enemy is not close, and if enemy is close then move enemy away."

(gif of loading, then 1 water, then 2 enemy, then 3 character, with When created, if enemy is blah blah, with arrow pointing to enemy from this script block)

This will work fine, because Enemy is created before Character is, so it already exists by the time Character is trying to get information about it.

Example 2:

"When Character is created, make sure Boat is moved directly under Character."

(gif of loading, then 1 water, then 2 enemy, then 3 character, with When created, set position of boat, with arrow pointing to a question mark from this script block, ??? where is boat? it doesn't exist!)

This won't work because Boat doesn't exist when Character is trying to move it. This will break the game, and you will see an error message like this:

(error message here)

Example 3:

"When Enemy is created, move Enemy to 100x, 100y."

(gif of loading, then 1 water, then 2 enemy, with When created, set position of enemy, with arrow pointing to enemy)

This will work because Enemy isn't trying to get information about anything that may or may not exist yet, it's only doing something to itself -- and it know's itself exists!

results matching ""

    No results matching ""