在Haxe的if语句中使用对象的存在

问题描述 投票:3回答:1

你能否使用对象的存在作为Haxe中if语句的条件?如果是这样,怎么样?

var b : Bullet = collide("bullet", x, y);
if (b) {
  b.destroy();
}

我也尝试过对抗Null类型,但这似乎不起作用。

if-statement condition haxe
1个回答
4
投票

正如kirilloid在评论中提到的那样,尝试检查b是否为空:

var b : Bullet = collide("bullet", x, y);
if (b != null) {
  b.destroy();
}

由于多种原因,决定Haxe不要使用if(b)语法。你可以在Google Groups: Test if exists找到关于这个主题的讨论。

© www.soinside.com 2019 - 2024. All rights reserved.