• 追加された行はこの色です。
  • 削除された行はこの色です。
#author("2021-05-19T00:38:30+09:00","","")
#author("2021-05-19T01:12:06+09:00","","")
[[FrontPage]]

*hspのbeginnerさん向けのページ [#v2acc15d]

**hspのインクリメント [#nc5bd553]

クックブックに載ってました

 a = 10
 a+
 mes a
 a++
 mes a
 // +a error
 // ++a error
 b = 10
 b-
 mes b
 b--
 mes b
 // -b error
 // --b error

a++ a+ がインクリメント 
--a -aはerrorです
「a++ a+」 がインクリメント 
「++a +a」はerrorです

b-- b- がデクリメント
--b -b はerrorです
「b-- b-」 がデクリメント
「--b -b」 はerrorです

**hsoの論理和 [#d7b985ac]

hspでは論理演算子は全部ビット演算子です

orはどっちにしろ同じように動くので特に気にしなくても動きます

 repeat 4
 if (cnt&1)&(cnt&2):mes cnt
 loop
 mes "////////////////////////////////"
 repeat 4
 if cnt&1{
 	if cnt&2:mes cnt
 }
 loop
 mes "////////////////////////////////"
 repeat 4
 if (cnt and 1)and(cnt and 2):mes cnt
 loop
 mes "////////////////////////////////"
 repeat 4
 if cnt and 1{
 	if cnt and 2:mes cnt
 }
 loop

こういう書き方もあります

elseがややこしくなるんですけど

クックブックで使ってました

 repeat 4
 if (cnt&1):if (cnt&2):mes cnt
 loop
 mes "////////////////////////////////"
 repeat 4
 if (cnt and 1):if (cnt and 2):mes cnt
 loop

3&1は1で3&2は2でビットが違うのでビット演算&の結果は0になるんですね

ただ1も2も0ではないのでifを繋げると真になります

こういう関数を作って使うと便利っす

 #define true 1
 #define false 0
 #module
 #defcfunc is_true int p
 	if p == 0:return 0
 	return 1
 #defcfunc l_and int p1,int p2,local loc1,local loc2
 	loc1 = is_true(p1)
 	loc2 = is_true(p2)
 	return loc1 && loc2
 #global
 repeat 4
 if is_true(cnt&1) && is_true(cnt&2){
 	mes cnt
 }
 loop
 mes "/////////////////////////"
 repeat 4
 if l_and((cnt&1),(cnt&2)):mes cnt
 loop
注=が上手く表示出来なくて全角となっております

**repeat の 罠 [#na56016a]

repeat使用時のcntはローカル変数です

なので呼び出す度に新しい cnt を生み出します

loopを呼び出すと消えるかんじ

 *start
 repeat 10
 goto *start
 loop

こんなかんじでerrorが起きます

この例は稀でしょうが

repeat loopの間でreturnするとerrorが起きます

ちなみにforのカウンタはグローバル変数なので

forを使えばerrorは起きません

 tmp=0
 *start
 for i,0,10,1
 tmp++
 title ""+tmp
 await 1
 goto *start
 next
注=が上手く表示出来なくて全角となっております