How to use variables from multiple scenes?

Discussion in 'Mod Discussions' started by trialq, July 13, 2014.

  1. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    In auto factory, a function needs to know the variables from live_game (including eco and some others, model.maxEnergy, model.maxMetal etc), and the status of a toggle I put in live_game_options_bar. Before the last big patch it worked because the options bar was not in its own scene. I moved the toggle code from the object in live_game to an object in live_game_options_bar to get it working with the new scene:
    Code:
    var tAutoFactory_op_bar = (function () {
    
         var tAutoFactory_op_bar = {};
         tAutoFactory_op_bar.active = ko.observable(true);
    
        return tAutoFactory_op_bar;
    })();
    
    (function () {
      //visible to knockout
      model.tAutoFactory_op_bar = tAutoFactory_op_bar;
    
      //add toggle to ui
       $(".div_ingame_options_bar").prepend("<div class=\"btn_ingame_options div_af_toggle_cont\"><a href=\"#\" data-bind=\"click: function () { model.tAutoFactory_op_bar.active(!model.tAutoFactory_op_bar.active()) }\"><!-- ko if: model.tAutoFactory_op_bar.active() --><img src=\"coui://ui/mods/tAutoFactory/live_game/af_on.png\" /><!-- /ko --><!-- ko ifnot: model.tAutoFactory_op_bar.active() --><img src=\"coui://ui/mods/tAutoFactory/live_game/af_off.png\" /><!-- /ko --></a></div>");
    
    })();
    Unfortunately, coherent doesn't magically allow the tAutoFactory object in live_game to see the tAutoFactory_op_bar object in live_game_options_bar. How can this be solved?
  2. Mereth

    Mereth Active Member

    Messages:
    330
    Likes Received:
    164
    pure guessing : you need to communicate between scenes with events using your own handlers
    trialq likes this.
  3. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    A scene is a separate process (there is what, 30-some of them during play now) I've not noticed any any abstraction in the code that attempts to put a facade over that fact. (Might be an interesting ko extension) You're going to have to send messages and set up handlers, just like every other scene in the game.
    trialq likes this.
  4. proeleert

    proeleert Post Master General

    Messages:
    1,681
    Likes Received:
    1,656
    Indeed check pastats or hotbuild2 for examples

    search for api.Panel.message(....);
    trialq likes this.
  5. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    Awesome, thanks for the quick responses. It seems it's time to learn how to use handlers.

    They look pretty easy actually, I've skipped them so far in my how to bodge through javascript adventures :p

Share This Page