What Does the Player Want to Do?
In Sheep Rancher and in certain minigames in Scary Game,
the player can press a key to cause an effect. For example, the
singing game in Scary Game allows the player to push a key
from 1 to 8 and sing a corresponding note.
This is all thanks to the key is pressed
command. It seems intimidating... after all, what's a "scancode," anyway?
It's not as hard as it seems, though. The Plotscripting Dictionary provides
us with a handy list
include, game.hsi #replace "game" with your filename
define constant,begin #scancodes
set variable (whichkey,0)
while (whichkey == 0) do
if (keyispressed(key_a)) then (setvariable(whichkey,1))
if (keyispressed(key_b)) then (setvariable(whichkey,2))
if (keyispressed(key_c)) then (setvariable(whichkey,3))
if (whichkey==1) then (showtextbox(5)) #a
if (whichkey==2) then (showtextbox(6)) #b
if (whichkey==3) then (showtextbox(7)) #c
Remember OHR Millionaire? That used a script that is
basically a much more complicated version of the script shown
And if you remember the script that made an NPC appear in front
of you, then you've just learned how to make Sheep Rancher.
Maybe you don't realize it, but you have learned 80% of the scripting
techniques used in Sheep Rancher:
Doing something when a key is pressed
Making an NPC appear in front of you
Figuring out where the NPCs are
So if you know how to do each part by itself, what's left?
Integration. Now we're going to take a big step into
very complex scripting. Look at the following excerpt
from a Way of the Wizard script.
if ( (key is pressed (key_b))) then (if (check tag(tag:Hero Att)==false)
then (if (check tag(tag:Blast)) then
set tag(tag:Hero Att,on)
set npc position(35,herox(me),heroy(me)--1)
if (hero direction(me)==west)
then (set npc position(35,herox(me)--1,heroy(me)))
if (hero direction(me)==north)
then (set npc position(35,herox(me),heroy(me)--1))
if (hero direction(me)==east)
then (set npc position(35,herox(me)+1,heroy(me)))
if (hero direction(me)==south)
then (set npc position(35,herox(me),heroy(me)+1))
There's obviously more to this thing called "plotscripting" than
it seems. (The excerpt above is taken from a 235-line -- and growing -- script that
runs constantly in the background.) Don't worry, though -- we're not
done yet. Let's dissect that script.
The script launches the Blast Crest's blast attack. It's important to know
what the script is meant to do before analyzing it.
It has the key is pressed command again.
This time, it makes sure you have the "Blast Crest," which you need in order to
use the attack.
It changes the palette and picture of NPC 35, the NPC used for the attack.
This is because the same NPC is used for every attack, and every attack looks different.
It places NPC 35 in front of the hero -- does that script look familiar?
It sets the variable attID. The attack ID
tells the other scripts which attack is being used. If you use the Fire Crest on
the Ice Temple boss, for example, it will apply weakness.
It calls the script attack, which animates
the NPC, senses if enemies are nearby, does the death animation for dead enemies,
gives money for defeating enemies, gives damage to bosses, checks if they
die, sets the appropriate tags if they die, gives you more money for killing them,
and makes the attack NPC disappear, all in 85 (and growing) lines of code.
Fortunately, we aren't even going to attempt to look at the attack script.
The point of all this is that, while it's nice to know how to use all the
commands individually, it's much more impressive when you are able to integrate
all of them into a single game.
As always, practice makes perfect. You don't need to make another Sheep Rancher,
but see if you can make a game where pressing a button puts an NPC in front of you.
You'll need to use the
to make sure that the script is always running.
That's all for now. Get that script working before moving on to the next lesson.
Return to Main Menu