0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Minecraft JE DataPack]Nullを検知する方法。

Posted at

初めに

みなさん、Nullって知ってますか?
そう、あのNullです。
何にも値が入っていない状態のことです。
今回はそんなNullをmcfunctionで検知する方法です。

本題

Nullの検知法。

まぁ、やっぱりmcfunction、普通に下の感じで検知なんてできません。

execute if score @s reizo.test matches Null

まぁ...まず、mcfunctionには、Nullって言葉がありません。
「え?じゃあどうやって検知するの?」
こういう時に使うのが、そう。unlessです。
どうやって使うのかというと...

execute unless score @s reizo.test matches -2147483648..2147483647

これで出来ます。
では...解説していきましょう。

解説

まず、unless。
これは、条件が達成されていないときに動くものです。
例えば、

execute unless score @s reizo.test matche 1

だったら。
これはスコアreizo.testが1ではないときに動くということです。
2でも動くし3でも動く、とにかく1以外なら動きます。

では、次、値の解説と行きます。

-2147483648..2147483647

とありますが、「なんでこんな微妙な数?」と思った方もいるでしょう。
実は、この数はスコアの最小値から最大値なんです。

そう、これをすることによってスコアに値が入っていないとき(最小値から最大値に合わないとき)だけコマンドを動かす ということができるんです。
これって要するに、Nullを検知出来ているわけですよね。

終わりに

スコアIDやInit処理などの応用も出来るので、覚えておいて損はないと思います。
それでは、また次の記事で会いましょう...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?