SkQueryの演算子について

if check [player is online]->[player has permission "test"]:
if check [player is online]->[player has permission "test"]:
このような構文をskunityで見つけたのですが、これ関連の事を調べても全然出てきません 詳しく知っている方がいれば教えてほしいです できれば使い方なども教えていただければ幸いです ソース
9 Replies
あお
あおOP3y ago
三項演算子というのですね
mirageeeeeeeeeeeeeeeeeeeeeeeeeee
これはラムダ式です 三項演算子は
(条件式) ? (trueの時) : (falseの時)
(条件式) ? (trueの時) : (falseの時)
というように記述するもので、
return {_var} > 1 ? "1よりでかい" : "1以下"
return {_var} > 1 ? "1よりでかい" : "1以下"
などと書けます
あお
あおOP3y ago
なるほど
function f(a: number):
return {_a} > 1 ? "1よりでかい" : "1以下"

send "結果: %f(0.5)%"
function f(a: number):
return {_a} > 1 ? "1よりでかい" : "1以下"

send "結果: %f(0.5)%"
結果: 1以下 となるわけですか
mirageeeeeeeeeeeeeeeeeeeeeeeeeee
この構文は、処理を連結することができます
#expressionやeffectの連結
do [send "test"]->[give player diamond]
#expressionやeffectの連結
do [send "test"]->[give player diamond]
#conditionの連結
return check [player has diamond]->[player is op]
#conditionの連結
return check [player has diamond]->[player is op]
そうなります。また、これをラムダ式を用いて
function f(a: number):
return check [{_a} > 1]

send "結果: %f(0.5)%"
function f(a: number):
return check [{_a} > 1]

send "結果: %f(0.5)%"
とすることで、booleanを返す処理を1行で記述できます
あお
あおOP3y ago
なるほど
mirageeeeeeeeeeeeeeeeeeeeeeeeeee
skripthub等でlambdaと検索することで関連の構文がいくつか出てきます 注意として、一行が長くなるとskriptの読み込みの際の構文解析にかなり時間がかかります
あお
あおOP3y ago
ここら辺を教えていただきたいです この場合どのような動作をするのでしょうか?
mirageeeeeeeeeeeeeeeeeeeeeeeeeee
前者の場合、
send "test"
give player diamond
send "test"
give player diamond
と記述した場合と同様の処理が行われます。 つまり、これまで1行ずつ書いていたものを1文にまとめられるようになるという事です。 後者の場合、それぞれの条件全てに合致するかを調べることができます 今回の場合、以下のコードと同様の処理をします
if player has diamond:
if player is op:
return true
else:
return false
else:
return false
if player has diamond:
if player is op:
return true
else:
return false
else:
return false
ただ、skriptの2.7.0から
# all conditions must pass
if:
condition 1
condition 2
then:
do stuff

# at least one condition must pass
if any:
condition 1
condition 2
then:
do stuff

# it can also be used in else-if statements
if 1 + 1 = 3:
do stuff that will never actually be done
else if:
condition 1
condition 2
then:
do stuff
else:
do stuff
# all conditions must pass
if:
condition 1
condition 2
then:
do stuff

# at least one condition must pass
if any:
condition 1
condition 2
then:
do stuff

# it can also be used in else-if statements
if 1 + 1 = 3:
do stuff that will never actually be done
else if:
condition 1
condition 2
then:
do stuff
else:
do stuff
このようなものが追加されたので、2.7.0を使うのであればskqueryのものを使用する必要はありません
あお
あおOP3y ago
なるほど 最初に書いた
if check [player is online]->[player has permission "test"]:
if check [player is online]->[player has permission "test"]:
と同じように使うには
if:
player is online
player has permission "test"
then:
effect...
if:
player is online
player has permission "test"
then:
effect...
というわけですか ありがとうございました

Did you find this page helpful?