public override void ResolveReferences(Story context)
{
if (isEmpty || isEnd || isDone)
{
return;
}
if (targetContent)
{
runtimeDivert.targetPath = targetContent.runtimePath;
}
// Resolve children (the arguments)
base.ResolveReferences(context);
// May be null if it's a built in function (e.g. TURNS_SINCE)
// or if it's a variable target.
var targetFlow = targetContent as FlowBase;
if (targetFlow)
{
if (!targetFlow.isFunction && this.isFunctionCall)
{
base.Error(targetFlow.name + " hasn't been marked as a function, but it's being called as one. Do you need to delcare the knot as '== function " + targetFlow.name + " =='?");
}
else if (targetFlow.isFunction && !this.isFunctionCall && !(this.parent is DivertTarget))
{
base.Error(targetFlow.name + " can't be diverted to. It can only be called as a function since it's been marked as such: '" + targetFlow.name + "(...)'");
}
}
// Check validity of target content
bool targetWasFound = targetContent != null;
bool isBuiltIn = false;
bool isExternal = false;
if (target.numberOfComponents == 1)
{
// BuiltIn means TURNS_SINCE, CHOICE_COUNT, RANDOM or SEED_RANDOM
isBuiltIn = FunctionCall.IsBuiltIn(target.firstComponent);
// Client-bound function?
isExternal = context.IsExternal(target.firstComponent);
if (isBuiltIn || isExternal)
{
if (!isFunctionCall)
{
base.Error(target.firstComponent + " must be called as a function: ~ " + target.firstComponent + "()");
}
if (isExternal)
{
runtimeDivert.isExternal = true;
if (arguments != null)
{
runtimeDivert.externalArgs = arguments.Count;
}
runtimeDivert.pushesToStack = false;
runtimeDivert.targetPath = new Runtime.Path(this.target.firstComponent);
CheckExternalArgumentValidity(context);
}
return;
}
}
// Variable target?
if (runtimeDivert.variableDivertName != null)
{
return;
}
if (!targetWasFound && !isBuiltIn && !isExternal)
{
Error("target not found: '" + target + "'");
}
}