Trigger condition parameters

0 favourites
  • 3 posts
From the Asset Store
Game Triggers is as versatile as a Swiss army knife, and will be a great resource for any type of game you're creating.
  • Hello.

    I'm working on an ink integration plugin for Construct 3.

    I managed very well on my own for a while but now am faced with a very small road block. I have workarounds but I also have questions. Here are the problems.

    Ink is a language/library for interactive storytelling, and allows to use 'variable watchers' to register a javascript callback to be called when a story variable changes. I would like to use a Construct Event Trigger as an end-user API for this.

    I am facing two issues:

    1. I need to know in advance which variables to watch.

    I can do this with a dedicated action to start watching a variable, but it's not ideal. If there's some way to generate some 'startup' function based on the event sheet content at compile time, it would be way better, but I have not found anything like that.

    For now I'm using a separate 'start watching variable' action. I have no hard-counters against this, it's just an extra step for the end user.

    2. I want to trigger a c3 trigger condition, telling it which variable has changed and what the new values are.

    My 'start watching' action looks like this:

    StartObservingVariable(name) {
     this._story.ObserveVariable(name, (name, new_value) => {
     this.Trigger(C3.Plugins.PLUGIN_ID_PLACEHOLDER.Cnds.VariableChanged)
     });
    }
    

    I have no idea how to tell the trigger condition which variable has changed.

    The condition looks like this in aces.json:

    {
     "id": "var-changed",
     "scriptName": "VariableChanged",
     "isTrigger": true,
     "params": [{"id": "var-name","type": "string"}]
    }
    

    where the given name is the ink variable that will need to have changed for this specific trigger block to fire.

    The corresponding function would look like this (basic idea):

    VariableChanged(nameFromEventSheet, nameFromTriggerCall) {
     return (nameFromEventSheet == nameFromTriggerCall);
    }
    

    The core of my goal is to have a simple trigger condition fire when "this variable has changed". I could do this with a fake trigger and a living dictionary of changed ink variables that I would populate in my watcher callback and then read on each tick to compare against the name given as condition parameter, and that probably is what I will end up doing, but I found it very troubling to not really be able to give a parameter to my trigger condition. Something like this.Trigger(C3.Plugins.PLUGIN_ID_PLACEHOLDER.Cnds.VariableChanged, myvalue)

    TL;DR: Is there a way to give parameters to a trigger condition? If not, how hard would it be to implement?

  • 1. I need to know in advance which variables to watch.

    I don't think there's a better way to do this than your proposed "start watching variable" action.

    TL;DR: Is there a way to give parameters to a trigger condition?

    The built-in addons handle this by just assigning a value to a property (e.g. this._param = someParam) before running Trigger(), and checking the value of this._param in the trigger method.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the answers! I guess my "workarounds" are the best options I have then.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)