getPropertyValue method
int
getPropertyValue(
- int pnum
)
Implementation
int getPropertyValue(int pnum) {
var propNum = 999999;
int addr = propertyTableStart;
while (propNum > pnum) {
propNum = propertyNumber(addr);
var len = ZMachine.verToInt(Z.engine.version) <= 3 ||
!BinaryHelper.isSet(Z.engine.mem.loadb(addr), 7)
? propertyLength(addr)
: propertyLength(addr + 1);
//not found (ref 12.4.1)
if (len == 0) {
return GameObject.getPropertyDefault(pnum);
}
if (propNum == pnum) {
//ding ding ding
if (len > 2) {
throw GameException(
'Only property length of 1 or 2 is supported by this function: $len');
}
if (len == 1) {
return Z.engine.mem.loadb(addr + 1);
} else {
return Z.engine.mem.loadw(addr + 1);
}
}
//skip to the next property
if (ZMachine.verToInt(Z.engine.version) <= 3) {
addr += (len + 1);
} else {
//if property len > 2, account for the second
//size byte in the header
addr += (len + ((len > 2) ? 2 : 1));
}
}
//return default property instead (ref 12.4.1)
return GameObject.getPropertyDefault(pnum);
}