不幸的是,沒有T在CAPL的ypedef。
enum
是最接近你可以得到關於布爾值。
下面的代碼示出了這樣enum
的用法:
variables
{
enum Bool {
true = 1,
false = 0
};
}
on Start {
enum Bool state;
// setting the value
state = true;
// accessing the integer value
write("state (integer value): %d", state); // prints "1"
// accessing the value identifier
write("state (value identifier): %s", state.name()); // prints "true"
// usage in if-statement
if (state == true) {
write("if-statement: true");
} else {
write("if-statement: false");
}
// usage in switch-statement
switch (state) {
case true:
write("switch-statement: true");
break;
case false:
write("switch-statement: false");
break;
default:
write("switch-statement: undefined");
break;
}
}