Start!

Step1

Step2

Step3

Step4

Step5

Step6

Step7

Step8

Final

Special thanks

Cover


step8: More advanced condition judgment

The end of this "Introduction to HSP" is finally approaching. After that, if you master the function unique to the script called condition judgment, the basic part is over. After that, you will be able to make various software depending on the application.

When it comes to conditional judgment, I have a feeling that it is likely to make some difficult judgment, but that is,

"Compare variables with numbers"

It is. And as a result of the comparison, we do something different ... That is the processing unique to scripts, and it is a point that can be applied.

In HSP, there is only one instruction to judge the condition. Just remember this one. But before that, there's something to remember.

In HSP, the principle of script is to write one instruction on one line and execute it in order from the first line, but in fact,

You can write multiple instructions on one line

It is. But I haven't said it before because doing it from the beginning complicates the script and makes it hard to see. I'll explain how to write multiple instructions on one line, but if you put too many instructions on one line more than necessary, you will end up with a spaghetti script that you won't understand at all later. Please use it with caution. So, to write multiple instructions on one line, simply



Multiple instructions can be written on one line by separating them with ": (colon)"



It was. That is,

x=150
y=100
pos x,y


The three-line script,

x=150:y=100:pos x,y

If you write, it will fit in one line. If this is hard to see,

x=150 : y=100 : pos x,y

You can freely open a space like this. Writing multiple instructions on one line like this is called " multi-statement ". With this, the density of the script will increase and it will look cool. However, please try to aim for a script that is easy to read.

Now that I've learned " multi-statement ", I'll return to the conditional judgment. The only instruction for conditional judgment, it is



if conditional expression: An instruction to be executed when the condition is correct.


Here comes the mysterious word conditional expression. That means



Conditional expression

Meaning

Variable name = Numerical value

Variable contents and numbers are the same

Variable name! Numerical value

Variable contents and numbers are not the same

Variable name & lt; Numeric value

Numbers are larger than the contents of variables

Variable name & gt; Numeric value

Numbers are smaller than the contents of variables


It's like this. The conditional expression specifies the conditions for comparing variables and numbers. The criteria for judging the conditions are

hen<10

Then, is the content of the variable hen less than 10? What can we do by making a conditional judgment with this ?? For example, by combining this with the "goto" instruction, you can create a loop that repeats the same thing a specified number of times.


kai=0

*kuri

mes "Repeat."
kai=kai+1
if kai < 10 : goto *kuri


In the above example, the contents of the variable kai are added one by one, and the same place is repeated by the "goto" command until it reaches 10. If you do this, you will see 10 "Repeat" messages. Here is one example using conditional judgment. Let's look at another example.


cls
kai=0
mes "Press the button"
button "PUSH",*gopush
button "END",*goend
stop

*gopush

kai=kai+1
stop

*goend

if kai > 0 : goto *owari
mes "Press the" PUSH "button at least once"
stop

*owari

cls
mes "You pressed the" PUSH "button" + kai + "times"
stop


In this example, two buttons, "PUSH" and "END", are displayed, and when the "END" button is pressed, the number of times "PUSH" has been pressed so far is displayed. However, if you press "END" before pressing "PUSH" even once, a message calling attention to "Please press the" PUSH "button at least once" is displayed. I'm making a decision.

In this way, it can also be used to determine whether a specific message has been read or a button has been pressed by entwining it with a variable.

By using conditional judgment in this way, you will be able to write more advanced scripts. It is an indispensable command when making a simple adventure game.

There are still many HSP commands available, but you should be able to create various software such as launchers, CG collections, media browsers, and venture games just by using the commands you have learned so far. First of all, let's learn the basics firmly and create a script within a reasonable range.

Now that I have explained the basics of how to write scripts, HSP still has various instructions and usages. That's ... let's talk about it at another time.

ONION software Copyright 1997-2009(c) All rights reserved.