Skip to content

Commit

Permalink
Also support != on divert targets
Browse files Browse the repository at this point in the history
  • Loading branch information
joethephish committed May 6, 2018
1 parent 575fdfa commit 1992b1b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/ParsedHierarchy/DivertTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void ResolveReferences (Story context)
// Only allowed to compare for equality

var binaryExprParent = usageParent as BinaryExpression;
if (binaryExprParent.opName != "==") {
if (binaryExprParent.opName != "==" && binaryExprParent.opName != "!=") {
badUsage = true;
} else {
if (!(binaryExprParent.leftExpression is DivertTarget || binaryExprParent.leftExpression is VariableReference)) {
Expand Down
6 changes: 5 additions & 1 deletion ink-engine-runtime/NativeFunctionCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,15 @@ static void GenerateNativeFunctionsIfNecessary()
AddListUnaryOp (Count, (x) => x.Count);
AddListUnaryOp (ValueOfList, (x) => x.maxItem.Value);

// Special case: The only operation you can do on divert target values
// Special case: The only operations you can do on divert target values
BinaryOp<Path> divertTargetsEqual = (Path d1, Path d2) => {
return d1.Equals (d2) ? 1 : 0;
};
BinaryOp<Path> divertTargetsNotEqual = (Path d1, Path d2) => {
return d1.Equals (d2) ? 0 : 1;
};
AddOpToNativeFunc (Equal, 2, ValueType.DivertTarget, divertTargetsEqual);
AddOpToNativeFunc (NotEquals, 2, ValueType.DivertTarget, divertTargetsNotEqual);

}
}
Expand Down

0 comments on commit 1992b1b

Please sign in to comment.