I have a bitset of 65 bits (CompassFlags) and wish to measure the amount of bits set, and have achievements for when 20, 40, or all 65 of these bits are set:
compass_count = 65
function CompassGet(index)
{
return bit(index % 8, CompassFlags + index / 8)
}
function CompassesGet()
{
compasses = []
for i in range(0, compass_count - 1)
{
array_push(compasses, CompassGet(i))
}
return compasses
}
function CreateMeasuredCompassTrigger(new_count, old_count=-1)
{
measured_condition = sum_of(CompassesGet(), s=>s) == new_count
if (old_count == -1)
{
when = always_true()
}
else
{
when = sum_of(CompassesGet(), s=>s) > old_count
}
return LoadProtection() &&
sum_of(CompassesGet(), s=>prev(s)) < new_count &&
measured(measured_condition, when=(when && LoadProtection()))
}
achievement(
id=394422,
title="Compass Novice",
description="Obtain 20 compasses.",
points=10,
trigger=CreateMeasuredCompassTrigger(20)
)
achievement(
id=394423,
title="Compass Enthusiast",
description="Obtain 40 compasses.",
points=10,
trigger=CreateMeasuredCompassTrigger(40, old_count=20)
)
achievement(
id=394424,
title="Compass Master",
description=format("Obtain all {0} compasses.", compass_count),
points=25,
trigger=CreateMeasuredCompassTrigger(compass_count, old_count=40)
)
The if construct is necessary in CreateMeasuredCompassTrigger because just using sum_of(CompassesGet(), s=>s) > old_count unconditionally triggers the "Expression is always true" error for Compass Novice, when the ideal behavior is that this condition should just get optimized away (and have the same behavior as always_true()) in the case of the "Compass Novice" achievement. This seems like a common use case which is made more clunky due to this error.
I feel this error should be moved to some sort of warnings list to warn about possible redundant code, but not block compilation.
I have a bitset of 65 bits (
CompassFlags) and wish to measure the amount of bits set, and have achievements for when 20, 40, or all 65 of these bits are set:The
ifconstruct is necessary inCreateMeasuredCompassTriggerbecause just usingsum_of(CompassesGet(), s=>s) > old_countunconditionally triggers the "Expression is always true" error for Compass Novice, when the ideal behavior is that this condition should just get optimized away (and have the same behavior asalways_true()) in the case of the "Compass Novice" achievement. This seems like a common use case which is made more clunky due to this error.I feel this error should be moved to some sort of warnings list to warn about possible redundant code, but not block compilation.