如何在 DXL 脚本中使用枚举?

发布于 2024-12-01 23:09:43 字数 153 浏览 5 评论 0原文

我想测试 DOORs 对象的枚举属性的值。这怎么能做到呢?在哪里可以找到描述此类基本功能的 DXL 文档?

if (o."Progress" == 0) // This does NOT work
{
  // do something
}

I'd like to test the value of an enumeration attribute of a DOORs object. How can this be done? And where can I find a DXL documentation describing basic features like this?

if (o."Progress" == 0) // This does NOT work
{
  // do something
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

惯饮孤独 2024-12-08 23:09:43

因此,经过两周和过期的赏金,我终于成功了。
可以根据需要将枚举属性分配给 int 或 string 变量。但是您必须分配给一个变量才能执行此类转换。当像我的示例中那样进行简单比较时,它不会被转换。因此,解决方案如下:

int tmp = o."Progress"
if (tmp == 0)
{
  // do something
}

当 tmp 是字符串时,可以与枚举文字进行比较。

那很容易。不是吗?和 在这里我终于找到了有关 DXL 手册的所有信息。

So after two weeks and an expired bounty I finally made it.
Enum-Attributes can be assigned to int or string variables as desired. But you have to assign to a variable to perform such a conversion. It is not casted when a mere comparison is done like in my example. So here comes the solution:

int tmp = o."Progress"
if (tmp == 0)
{
  // do something
}

When tmp is a string, a comparison to the enum literals is possible.

That was easy. Wasn't it? And here I finally found the everything-you-need-to-know-about-DXL manual.

半暖夏伤 2024-12-08 23:09:43

对于多值枚举,最好的方法是 if (isMember(o."Progress", "0")) {。单个和多个枚举变量的可能枚举被视为字符串,因此 Steve 的解决方案是单个枚举的最佳 dxl 方式。

For multi-valued enumerations, the best way is if (isMember(o."Progress", "0")) {. The possible enumerations for single and multi-enumeration variables are considered strings, so Steve's solution is the best dxl way for the single enumeration.

野生奥特曼 2024-12-08 23:09:43

您还可以执行

if(o."Progress" "" == "0")
{
   //do something
}

此操作,将属性值转换为字符串并将其与字符串 "0" 进行比较

You can also do

if(o."Progress" "" == "0")
{
   //do something
}

This will cast the attribute value to a string and compare it to the string "0"

枯叶蝶 2024-12-08 23:09:43

如果您正在谈论可从“编辑类型”框分配的“相关数字”,那么您需要首先获取枚举字符串在枚举中的位置,然后检索 EnumName[k].value

我不是 DXL 方面的专家,因此找到我所知道的索引的唯一方法是循环 1 : EnumName.size ,当你得到与枚举字符串,使用该循环索引值来检索枚举“相关编号”。

If you're talking about the "related number" that is assignable from the Edit Types box, then you'll need to start by getting the position of the enumeration string within the enum and then retrieve EnumName[k].value .

I'm no expert at DXL, so the only way to find the index that I know of off the top of my head is to loop over 1 : EnumName.size and when you get a match to the enumeration string, use that loop index value to retrieve the enumeration "related number."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文