1. Stuck, Having problems with creating your mod? Let us help you: Mod Support

Solved Start Scenario html, .js popup

Discussion in 'Mod Support' started by bidwars, Sep 1, 2016.

  1. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    132
    I am working on a mod to ask a question on the Start Scenario popup and then send the output to the mod .lua file in a function. The popup I am talking about is the one that comes up right before the scenario starts and has the Start button.

    It does not seem to work and nothing is showing in the debug log. This is the same as the template.html and template.js file.

    In the mod I have the .json file point to an html file "startHTML": "question.html",

    Here is my question.html file
    <!--
    <style type="text/css">
    .question_class {
    width: 100%;
    height:100%;
    }

    </style>

    <md-content class="question_class" layout="row" layout-align="left">
    <div layout="column" class="md-padding">
    This is my question file.</p>
    <div layout="row">
    <input type="text" ng-model="Num">
    <div layout>
    </select><br><br>
    <md-button class="md-primary md-raised" ng-click="CountNum(Num)">
    <md-icon class="material-icons">share</md-icon>
    Send Question
    </md-button>
    </div>
    <br>

    <pre>{{data | json}}</pre>

    </div>
    </div>
    </md-content>
    -->

    I would like to pass the answer back to my modname.lua file function so I have a question.js file.
    <!--
    angular.module('beamng.stuff')

    .controller('questionController', ['$log', '$scope', '$state', 'bngApi', function ($log, $scope, $state, bngApi) {
    var vm = this;

    bngApi.engineLua('extensions.loadModule("modname.lua")');
    // make sure we unload the lua module as well when this page is unloaded
    $scope.$on('$destroy', function () {
    bngApi.engineLua('extensions.unloadModule("modname.lua")');
    });

    // example data holder
    $scope.data = {};
    $scope.Num = '3';

    // example for a function call
    $scope.CountNum = function(arg1) {
    console.log("calling function with arg: ", arg1);
    // simple calls with no return value:
    bngApi.engineLua('modname.CountNum(' + bngApi.serializeToLua(arg1) + ')');

    // calls with return values:
    bngApi.engineLua('modname.CountNum(' + bngApi.serializeToLua(arg1) + ')', function (response) {
    console.log("got response from lua: ", response);
    $scope.$apply(function () {
    $scope.data = response;
    });
    });
    }
    }])
    -->
    --- Post updated ---
    just to note I don't have the <!-- in the real file.
     
  2. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,480
    No coding advice and very remedial understanding and interpretation here but are you trying to incorporate like a yes or no response to the scenario prompt? If so, I don't believe that's in the game yet.
     
  3. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    132
    It won't be a yes or no question but it will be an select options drop down at some point. Right now I am 'keeping it simple' and just sending a text value with a send button that calls a question.js file.
     
  4. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,480
    Yeah, the game doesn't have that capability yet I believe. However, you may be able to manipulate the code enough. Ask @tdev or @estama
     
  5. Saniamos revived

    Saniamos revived
    Expand Collapse
    Staff Member

    Joined:
    May 8, 2015
    Messages:
    14
    I am afraid that's not possible to do right now.

    There are several things standing in the way:
    1. We currently don't include custom js files. This means your js file is never loaded and therfore doesn't print anything to the log
    2. Due to the use of angulars ngInclude to include the custom html, the script tag doesn't work inside of your custom html and you'll not be able to load your js that way unfortunately
    3. Once this is finished we still somehow have to tell angular which controller to use for the html view.

    We'll discuss this further and with the next release it should be possible to add custom JS to the scenario start screen. I'll come back to you about how this will work then
     
    • Like Like x 2
  6. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    132


    I had a feeling it was not calling the custom .js file. But it sounds like you have that covered in the next update. Thanks for the reply!
     
    #6 bidwars, Sep 2, 2016
    Last edited: Oct 5, 2016
  7. Saniamos revived

    Saniamos revived
    Expand Collapse
    Staff Member

    Joined:
    May 8, 2015
    Messages:
    14
    So since the alst update you can add your custom js to the scenario start screen. For it to work you'll have to do this:
    1. add a "jsSource" field to your sceanrio json with the path pointing to your js file, the game will load it as soon as it's needed
    2. inside your js declare a controller like you already did :)
    it shoudl look smth. like this:

    Code:
    angular.module('beamng.stuff')
    .controller('questionController', ['$scope', function ($scope) {
      var vm = this;
      vm.test= 'text';
    }])
    3. Last but not least let the framework now where to use your js code by adding this into the parent node of your html file:

    HTML:
    <div ng-controller="questionController as questions">
    {{test.test}}
    </div>
    This should display your start screen with the inserted and extremly imaginitve text "text"

    Hope this helps :)
     
    • Like Like x 2
  8. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    132
    I will give the Controller a try.


     
  9. Saniamos revived

    Saniamos revived
    Expand Collapse
    Staff Member

    Joined:
    May 8, 2015
    Messages:
    14
    Hey :)

    just doing a follow up, did you get it working or can I help you with something?
     
  10. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    132
    Yes, I did get the value to pass over to the .lua file. Thank You!!

    --- Post updated ---
    Another question. Do you know why it will not find the question.js file if it is located in the mod folder? It only seems to find the file in the program /ui/ folder. The path that did not work is "jsSource" = "question.js".
     
  11. bidwars

    bidwars
    Expand Collapse

    Joined:
    Sep 23, 2014
    Messages:
    132
    I have already figured out the problem. To fix it I created a "ui" folder in my mod.zip file and then made the .json file point to the \ui\question.js file. In the .json file it looks like this:

    "jsSource": "question.js",
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice