Giter Club home page Giter Club logo

Comments (2)

daterre avatar daterre commented on August 18, 2024

A macro could work but unfortunately not as natively as yoursetGlobal example. Something like this:
<<setGlobal "someVar" "something">>
<<getGlobal "someVar">>

The easiest way to implement this would be via runtime macros:

[RuntimeMacro]
public void setGlobal(string globalVarName, StoryVar value)
{
	// Some static class or singleton
	GlobalVariables[globalVarName] = value;
}

[RuntimeMacro]
public StoryVar getGlobal(string globalVarName)
{
	return GlobalVariables[globalVarName];
}

Because you're using SugarCube, which doesn't have the concept of nesting macros, you'd probably need to use GlobalVariables directly if you need it in an expression, e.g.:

<<print "You have " + GlobalVariables["someVar"]>>

A better option would be to make a sync script that listens for standard variables' value changes and propagates them to other stories. You could do this in an update loop and compare each variable in Story.Vars to a list you saved in the previous frame (a bit tedious).

Actually, I might add an event to the Story object, sort of like this: Story.OnVariableChanged(Story story, string varName, StoryVar newValue, StoryVar previousValue). You could then register a single handler for all your stories and propagate the value to all of them.

from cradle.

BrodyB avatar BrodyB commented on August 18, 2024

Ah, yeah. I think I was moving away from that because I didn't think runtime macros received StoryVars, but rather what they cast down to? I'll give it a shot.

Thanks!

from cradle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.