That's a good opportunity to make sure we've got the right imports and
everything, and haven't made any typos. And since it's working, I'll do a git
Try This Yourself
Now do this much yourself: create a new plugin directory with mkplugin.sh , get
a Git repository set up for it, and add any functions and data that you think
you need. Refer back to earlier parts of the topic if you need a refresher on
Add the testing commands to @Command , even if you have real commands that
you're going to add as well. Again, small steps. You want to make small
functions that run by themselves, and get them right before continuing. Don't
try to flesh out the functions yet; just start with empty function bodies like
we did here.
Don't forget to do a gitcommit to “save your game” as you go along.
Filling In the Details: the spawnCows() Function
Now that we have a way to test it, let's move on to the guts of spawnCows() itself.
We noted earlier that we need to do the following:
Create our list of cows.
Spawn creeper cows and add them to our list.
Set up each creeper cow with a timer.
Listen for events to create and remove cows.
Let's take this one at a time. We already made the simple static list of cows,
so let's look at spawning.
We'll need to create some random cows. This raises a question: where should
we put them? All over the game? Near where you are? Right on top of your
friend's head? All of these choices may have their appeal.
One of the best things you can do when programming is to delay making
decisions. In many cases, you don't know the “right” answer, and you may
not know it for a while—or ever. But that's what function parameters are for:
we don't have to decide the details right now. Instead of implementing some
particular detail, pass that it in as a parameter. Now you don't have to decide,
and the function can be used with all sorts of different details.
So we need to change the temporary declaration we had in place for spawnCows()
and pass in something to indicate where we want these cows. What should
that look like?