Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/inkle/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lohse committed Apr 2, 2017
2 parents 17d2c35 + f24f520 commit 812eaaf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
16 changes: 12 additions & 4 deletions Documentation/RunningYourInk.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

Ink uses an intermediate `.json` format, which is compiled from the original `.ink` files. ink's Unity integration package automatically compiles ink files for you, but you can also compile them on the command line. See **Using inklecate on the command line** in the [README](http://www.github.com/inkle/ink) for more information.

The main runtime code is included in the `ink-engine.dll`, and we also have a dependency on the `Newtonsoft.Json.dll` library, which is also included in the integration package.

You may need to change API compatibility for .NET: Go into `Edit -> Project settings -> Player -> Other settings` and change API compatibility level from .NET 2.0 subset (the default) to .NET 2.0. (If you get the error `TypeLoadException: Could not load type 'Newtonsoft.Json.Linq.JArray' from assembly 'Newtonsoft.Json`..., this is what's wrong.)
The main runtime code is included in the `ink-engine.dll`.

We recommend that you create a wrapper MonoBehaviour component for the **ink** `Story`. Here, we'll call the component "Script" - in the "film script" sense, rather than the "Unity script" sense!

Expand Down Expand Up @@ -172,7 +170,17 @@ You can define game-side functions in C# that can be called directly from **ink*

The types you can use as parameters and return values are int, float, bool (automatically converted from **ink**’s internal ints) and string.


### Fallbacks for external functions

When testing your story, either in [Inky](https://github.com/inkle/inky) or in the [ink-unity integration](https://github.com/inkle/ink-unity-integration/) player window, you don't get an opportunity to bind a game function before running the story. To get around this, you can define a *fallback function* within ink, which is run if the `EXTERNAL` function can't be found. To do so, simply create an ink function with the same name and parameters. For example, for the above `multiply` example, create the ink function:

```
=== function multiply(x,y) ===
// Usually external functions can only return placeholder
// results, otherwise they'd be defined in ink!
~ return 1
```

## Debugging ink engine issues

The **ink** engine is still in a nascent stage (alpha!), and you may well encounter bugs, or unhelpful error messages and exceptions.
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![HipChat](http://www.inklestudios.com/img/ink-github-HipChat-widget.svg)](https://www.hipchat.com/gkq2pSLqU)
[![CI Status](http://img.shields.io/travis/inkle/ink.svg?style=flat)](https://travis-ci.org/inkle/ink)

Ink is [inkle](http://www.inklestudios.com/)'s scripting language for writing interactive narrative, both for text-centric games as well as more graphical games that contain highly branching stories. It's designed to be easy to learn, but with powerful enough features to allow an advanced level of structuring.
[Ink](http://www.inklestudios.com/ink) is [inkle](http://www.inklestudios.com/)'s scripting language for writing interactive narrative, both for text-centric games as well as more graphical games that contain highly branching stories. It's designed to be easy to learn, but with powerful enough features to allow an advanced level of structuring.

Here's a taster [from the tutorial](https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md).

Expand All @@ -26,6 +26,8 @@ Here's a taster [from the tutorial](https://github.com/inkle/ink/blob/master/Doc
* ... but I said nothing[] and <>
- we passed the day in silence.
- -> END

We'd recommend downloading [Inky, our ink editor](https://github.com/inkle/inky), and the follow [the tutorial](https://github.com/inkle/ink/blob/master/Documentation/WritingWithInk.md), if you want to give ink a try.

Broadly, the engine is made up of two components:

Expand Down
6 changes: 6 additions & 0 deletions ink-engine-runtime/VariablesState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public object this[string variableName]
return null;
}
set {

// This is the main
if (!_globalVariables.ContainsKey (variableName)) {
throw new StoryException ("Variable '" + variableName + "' doesn't exist, so can't be set.");
}

var val = Runtime.Value.Create(value);
if (val == null) {
if (value == null) {
Expand Down
6 changes: 4 additions & 2 deletions inklecate/ParsedHierarchy/FlowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ public override Runtime.Object GenerateRuntimeObject ()

var childFlowRuntime = childFlow.runtimeObject;

// First inner knot/stitch - automatically step into it
if (contentIdx == 0 && !childFlow.hasParameters) {
// First inner stitch - automatically step into it
// 20/09/2016 - let's not auto step into knots
if (contentIdx == 0 && !childFlow.hasParameters
&& this.flowLevel == FlowLevel.Knot) {
_startingSubFlowDivert = new Runtime.Divert ();
container.AddContent(_startingSubFlowDivert);
_startingSubFlowRuntime = childFlowRuntime;
Expand Down
31 changes: 28 additions & 3 deletions tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public void TestCallStackEvaluation()
{
var storyStr =
@"
=== eight
{ six() + two() }
-> END
Expand Down Expand Up @@ -336,7 +335,6 @@ public void TestConditionalChoiceInWeave()
{
var storyStr =
@"
== test ==
- start
{
- true: * [go to a stitch] -> a_stitch
Expand Down Expand Up @@ -1016,6 +1014,7 @@ public void TestIncrement()
public void TestKnotDotGather()
{
var story = CompileString(@"
-> knot
=== knot
-> knot.gather
- (gather) g
Expand Down Expand Up @@ -1045,6 +1044,7 @@ public void TestKnotTerminationSkipsGlobalObjects()
public void TestKnotThreadInteraction()
{
Story story = CompileString(@"
-> knot
=== knot
<- threadB
-> tunnel ->
Expand Down Expand Up @@ -1078,6 +1078,7 @@ THE END
public void TestKnotThreadInteraction2()
{
Story story = CompileString(@"
-> knot
=== knot
<- threadA
When should this get printed?
Expand Down Expand Up @@ -1168,6 +1169,7 @@ public void TestMultipleConstantReferences()
public void TestMultiThread()
{
Story story = CompileString(@"
-> start
== start ==
-> tunnel ->
The end
Expand Down Expand Up @@ -1243,6 +1245,7 @@ public void TestNonTextInChoiceInnerContent()
{
var storyStr =
@"
-> knot
== knot
* option text[]. {true: Conditional bit.} -> next
-> DONE
Expand All @@ -1264,6 +1267,7 @@ public void TestNonTextInChoiceInnerContent()
public void TestOnceOnlyChoicesCanLinkBackToSelf()
{
var story = CompileString(@"
-> opts
= opts
* (firstOpt) [First choice] -> opts
* {firstOpt} [Second choice] -> opts
Expand Down Expand Up @@ -1480,7 +1484,6 @@ In second.
public void TestReadCountAcrossThreads()
{
var story = CompileString(@"
=== empty_world ===
-> top
= top
Expand Down Expand Up @@ -1550,6 +1553,7 @@ public void TestReturnTextWarning()
public void TestSameLineDivertIsInline()
{
var story = CompileString(@"
-> hurry_home
=== hurry_home ===
We hurried home to Savile Row -> as_fast_as_we_could
Expand Down Expand Up @@ -1615,6 +1619,7 @@ public void TestSimpleGlue()
public void TestStickyChoicesStaySticky()
{
var story = CompileString(@"
-> test
== test ==
First line.
Second line.
Expand Down Expand Up @@ -1847,6 +1852,7 @@ public void TestTurnsSince()
public void TestTurnsSinceNested()
{
var story = CompileString(@"
-> empty_world
=== empty_world ===
{TURNS_SINCE(-> then)} = -1
* (then) stuff
Expand Down Expand Up @@ -2151,6 +2157,7 @@ public void TestWeaveOptions()
{
var storyStr =
@"
-> test
=== test
* Hello[.], world.
-> END
Expand All @@ -2170,6 +2177,7 @@ public void TestWhitespace()
{
var storyStr =
@"
-> firstKnot
=== firstKnot
Hello!
-> anotherKnot
Expand Down Expand Up @@ -2232,6 +2240,7 @@ public void TestTempGlobalConflict()
// Test bug where temp was being treated as a global
var storyStr =
@"
-> outer
=== outer
~ temp x = 0
~ f(x)
Expand Down Expand Up @@ -2425,6 +2434,22 @@ Another line.
Assert.AreEqual ("A line.\nAnother line.\n", story.ContinueMaximally ());
}

[Test ()]
public void TestSetNonExistantVariable ()
{
var storyStr =
@"
VAR x = ""world""
Hello {x}.
";
var story = CompileString (storyStr);

Assert.AreEqual ("Hello world.\n", story.Continue());

Assert.Throws<StoryException>(() => {
story.variablesState ["y"] = "earth";
});
}

// Helper compile function
protected Story CompileString(string str, bool countAllVisits = false, bool testingErrors = false)
Expand Down

0 comments on commit 812eaaf

Please sign in to comment.