Game Development Reference
In-Depth Information
Figure 5-19. The variable named myCustomScript of type VariablesTest
The type does not turn blue for the custom type.
7.
Drag the Sunflower (that also has the Variables Test component on it) onto
the bench's My Custom Script parameter.
If you are wondering why you might want access to the Sunflower's VariablesTest script, imagine
the following scenario: An alien zombie ray strikes the bench, causing it to give off a toxic essence
that turns Sunflowers into carnivorous monsters. At this point, the VariablesTest script on the bench
would change the Sunflower's Variables Test's Favorite Food value to something more fauna than
flora. It's a silly scenario, but it illustrates the concept of one object's script communicating with
another.
Creating Comments
There's one last thing to add to your first scripting efforts. Sometimes you can name a variable so
that it perfectly describes what it is for and what is done with it. Most of the time, that is not fully
possible without creating long and unwieldy names. It is also not unusual to revisit old code or
maybe even someone else's code and have to try and figure out what it is meant to do. This is where
comments come in.
Comments allow you to make notes and add explanations to your code. They may be strictly for
your own benefit, or they might be necessary when working with other people on a project where
they will want to understand how the code is designed to work. Typically, you make comments to
explain specific variables, to describe what functions are meant to do, or to make general notes
about what is happening in your code.
 
Search WWH ::




Custom Search