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.
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.
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.
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
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
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!
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
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".
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",