HSP sun HSP Programming Guide

HSP Guide [4]

Calculate operation

It is addition, subtraction, multiplication, and dividing calculation.

	mes 1+1

	mes 10-5

	mes 10*10

	mes 10/5

Addition and the subtraction use "+" and "-" of the one-byte character. And, multiplication and the dividing calculation use "*" of the one-byte character (asterisk) and "/" (slash). The under is a source where the calculation type made it make plainly.

	mes "1+1 = "+(1+1)+""

	mes "10-5 = "+(10-5)+""

	mes "10*10 = "+(10*10)+""

	mes "10/5 = "+(10/5)+""

Incidentally, let's calculate the remainder of the dividing calculation. "\" (back slash) of the one-byte character is used.

	mes 5\2

	mes "5/2 = "+(5/2)+", remainder "+(5\2)+""

Is there a person who thinks that it wants to get the answer of "2.5" without dropping below the decimal point of the calculation above "5/2" with hesitancy?

	mes 5.0/2

	mes "5/2 = "+(5.0/2)+""

It becomes an answer with the decimal point by this. The calculation type only has to be a numerical value of the decimal point. However, it is necessary to note it with ..the calculation of the decimal point.. in HSP. Please execute the under.

	mes 5/2.0

	mes "5/2 = "+(5/2.0)+""

It has become a numerical result with the remainder usually. The treatment of the decimal point by the calculation type is decided to HSP by the left first numerical value. This is useless if it doesn't do earnestly for remembrance' sake.

Calculation and priority level

It knows to say nothing of the priority level's there in the calculation sign of the calculation type. "*" and "/" are previously calculated from "+" and "-" in a word.

	mes 5+5*2

	mes "5+5*2 = "+(5+5*2)+""

If it wants to make addition and the subtraction calculated previously, the calculation type is usually bundled by parentheses of normal-width. It is the same idea as arithmetic.

	mes (5+5)*2

	mes "(5+5)*2 = "+((5+5)*2)+""

Random number generation of HSP

Random numbers are functions to present various numerical values. It can be said the one that the script shakes the one like dice if it says terribly and easily. The "rnd" function is used to generate random numbers with HSP. (Referer the control guide about button control.

	button "rnd", *ransu

	mes rnd(6)+1

"rnd" The parameter specified by the function is range (1-32768) of random numbers. Various numerical values return within the range of 0-5 (six numbers in a word) whenever the button is pushed because it specified six here. One is added up to it if it makes it in the dice style. However, the numerical value returns without fail whenever this does the compilation execution every time by the same pattern.


	button "rnd", *ransu

	mes rnd(6)+1

In this case, the "randomoze" instruction is declared first. The time of the personal computer is used when this is and the pattern of random numbers is generated completely disjointedly. However, the "randomize" instruction is called many times and.

< Prev | Next >


Welcome to HSP sun. Here is a site to introduces HSP, a free script language system.


Copyright(c) HSP sun [HSP]

inserted by FC2 system