Twine & Cradle,Using Cradle for Twine storytelling
I'm trying to use Twine's Cradle extension to begin doing branching dialogue in my game. I can't quite figure out how to initialize it. Here's what I've got so far.
This script is on a cube looking for the player to enter it. It can successfully detect when the player has entered and switch my bool to true accordingly. My question is... how in the heck do I get it to play my Twine story?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cradle;
using IStoryThread = System.Collections.Generic.IEnumerable<Cradle.StoryOutput>;
using Cradle.StoryFormats.Harlowe;
public class StoryCube : MonoBehaviour {
private bool storycubetriggered = false;
//HERE WE TRIGGER THE STORY CUBE BY WALKING INTO IT//
private void OnTriggerEnter(Collider storycollide)
{
if(storycollide.gameObject.name == "Player")
{
// Debug.Log("I'm so triggered rn");
storycubetriggered = true;
Debug.Log(storycubetriggered);
}
}
public partial class @TestStorySanctified : Cradle.StoryFormats.Harlowe.HarloweStory
{
#region Variables
// ---------------
public class VarDefs : RuntimeVars
{
public VarDefs()
{
}
}
public new VarDefs Vars
{
get { return (VarDefs)base.Vars; }
}
// ---------------
#endregion
#region Initialization
// ---------------
public readonly Cradle.StoryFormats.Harlowe.HarloweRuntimeMacros macros1;
@TestStorySanctified()
{
{
this.StartPassage = "Intro";
base.Vars = new VarDefs() { Story = this, StrictMode = true };
macros1 = new Cradle.StoryFormats.Harlowe.HarloweRuntimeMacros() { Story = this };
base.Init();
passage1_Init();
passage2_Init();
}
}
// ---------------
#endregion
// .............
// #1: Intro
void passage1_Init()
//{
{
this.Passages[@"Intro"] = new StoryPassage(@"Intro", new string[] { } , passage1_Main);
}
IStoryThread passage1_Main()
{
yield return link("On the night of the swollen moon, a hunter, his watchdog, and their hound embark on a journey.", "Select", null);
yield return lineBreak();
yield break;
}
// .............
// #2: Select
void passage2_Init()
{
this.Passages[@"Select"] = new StoryPassage(@"Select", new string[] { } , passage2_Main);
}
IStoryThread passage2_Main()
{
yield return link("Luthor", "Luthor", null);
yield return lineBreak();
yield return link("Edgar", "Edgar", null);
yield return lineBreak();
yield return link("Mutton", "Mutton", null);
yield return lineBreak();
yield break;
}
}
}
// private void Update()
// {
// Debug.Log("Story Cube is Updating");
//}
,Hey there. I'm somewhat new to scripting in general, but I'm trying to make a storytelling/platformer hybrid, with the story sections utilizing Twine. To integrate, I'm trying to use Cradle, but I'm not quite understanding how to implement it or get it to work within Unity at all. Has anyone used Twine or Cradle inside Unity?
In particular, I've imported a sample story into my project and have it linked to a simple cube. I can detect when the player touches the cube with onTriggerEnter, and have a bool that toggles on when that happens. I would like to have my story play when the bool = true, but I can't quite decide where it should go. I think I'm probably overstepping my learning by a little bit here, but hey I you have to dive in the deep end to learn how to swim.
Anyway here's what I have so far.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cradle;
using IStoryThread = System.Collections.Generic.IEnumerable<Cradle.StoryOutput>;
using Cradle.StoryFormats.Harlowe;
public class StoryCube : MonoBehaviour {
private bool storycubetriggered = false;
//HERE WE TRIGGER THE STORY CUBE BY WALKING INTO IT//
private void OnTriggerEnter(Collider storycollide)
{
if(storycollide.gameObject.name == "Player")
{
// Debug.Log("I'm so triggered rn");
storycubetriggered = true;
Debug.Log(storycubetriggered);
}
}
public partial class @TestStorySanctified : Cradle.StoryFormats.Harlowe.HarloweStory
{
#region Variables
// ---------------
public class VarDefs : RuntimeVars
{
public VarDefs()
{
}
}
public new VarDefs Vars
{
get { return (VarDefs)base.Vars; }
}
// ---------------
#endregion
#region Initialization
// ---------------
public readonly Cradle.StoryFormats.Harlowe.HarloweRuntimeMacros macros1;
@TestStorySanctified()
{
{
this.StartPassage = "Intro";
base.Vars = new VarDefs() { Story = this, StrictMode = true };
macros1 = new Cradle.StoryFormats.Harlowe.HarloweRuntimeMacros() { Story = this };
base.Init();
passage1_Init();
passage2_Init();
}
}
// ---------------
#endregion
// .............
// #1: Intro
void passage1_Init()
//{
{
this.Passages[@"Intro"] = new StoryPassage(@"Intro", new string[] { } , passage1_Main);
}
IStoryThread passage1_Main()
{
yield return link("On the night of the swollen moon, a hunter, his watchdog, and their hound embark on a journey.", "Select", null);
yield return lineBreak();
yield break;
}
// .............
// #2: Select
void passage2_Init()
{
this.Passages[@"Select"] = new StoryPassage(@"Select", new string[] { } , passage2_Main);
}
IStoryThread passage2_Main()
{
yield return link("Luthor", "Luthor", null);
yield return lineBreak();
yield return link("Edgar", "Edgar", null);
yield return lineBreak();
yield return link("Mutton", "Mutton", null);
yield return lineBreak();
yield break;
}
// .............
}
}
// private void Update()
// {
// Debug.Log("Story Cube is Updating");
//}
what even is twine and cradle?? looks like way to work to me to be considered an extension or at least one that would simplify things and save time..
Your answer
![](https://koobas.hobune.stream/wayback/20220612171123im_/https://answers.unity.com/themes/thub/images/avi.jpg)