Skip to content

Commit

Permalink
Ability to pass arguments to knots (or functions) from the game.
Browse files Browse the repository at this point in the history
  • Loading branch information
joethephish committed Mar 9, 2017
1 parent 0d63a52 commit 6770c74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 7 additions & 4 deletions ink-engine-runtime/Story.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,14 +1099,17 @@ bool PerformLogicAndFlowControl(Runtime.Object contentObj)
///
/// </summary>
/// <param name="path">A dot-separted path string, as specified above.</param>
public void ChoosePathString(string path)
/// <param name="arguments">Optional set of arguments to pass, if path is to a knot that takes them.</param>
public void ChoosePathString (string path, params object [] arguments)
{
ChoosePath (new Path(path));
state.PassArgumentsToEvaluationStack (arguments);
ChoosePath (new Path (path));
}


internal void ChoosePath(Path path)
internal void ChoosePath(Path p)
{
state.SetChosenPath (path);
state.SetChosenPath (p);

// Take a note of newly visited containers for read counts etc
VisitChangedContainersDueToDivert ();
Expand Down
12 changes: 7 additions & 5 deletions ink-engine-runtime/StoryState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -810,20 +810,22 @@ internal void StartExternalFunctionEvaluation (Container funcContainer, params o
callStack = new CallStack (funcContainer);
callStack.currentElement.type = PushPopType.Function;

// Change the callstack the variableState is looking at to be
// this temporary function evaluation one. We'll restore it afterwards
variablesState.callStack = callStack;

// By setting ourselves in external function evaluation mode,
// we're saying it's okay to end the flow without a Done or End,
// but with a ~ return instead.
_isExternalFunctionEvaluation = true;

PassArgumentsToEvaluationStack (arguments);
}

internal void PassArgumentsToEvaluationStack (params object [] arguments)
{

// Pass arguments onto the evaluation stack
if (arguments != null) {
for (int i = 0; i < arguments.Length; i++) {
if (!(arguments [i] is int || arguments [i] is float || arguments [i] is string)) {
throw new System.ArgumentException ("ink arguments when calling EvaluateFunction must be int, float or string");
throw new System.ArgumentException ("ink arguments when calling EvaluateFunction / ChoosePathStringWithParameters must be int, float or string");
}

PushEvaluationStack (Runtime.Value.Create (arguments [i]));
Expand Down

0 comments on commit 6770c74

Please sign in to comment.