UI App Help

Discussion in 'Content Creation' started by Galahir950, Oct 15, 2014.

  1. Galahir950

    Galahir950
    Expand Collapse

    Joined:
    Oct 11, 2014
    Messages:
    20
    I am trying to create a UI app that would show you the current G-Forces that your car is experiencing, eventually making the app act like the performance test app, but I am having issues getting it to work.

    App.js
    HTML:
    function gForcesList() {}
    
    gForcesList.prototype.initialize = function(){
        this.gDiv = $('<div></div>').appendTo(this.rootElement).addClass('gDiv');
        this.labelDiv = $('<div></div>').appendTo(this.rootElement).addClass('labelDiv');
    
    };
    
    gForcesList.prototype.update = function (streams) {
        //convert to G
        var gForces = {};
        $.each(streams.sensors, function(index, val) {
            gForces[index] = val / 9.81;
        });
    
        this.gDiv.html(rSet(gForces, 4, "0"));
        this.labelDiv.html("G-Forces");
    };
    
    
    In game, this is what shows up
    In Game.png
    The gForces variable,
    HTML:
        var gForces = {};
        $.each(streams.sensors, function(index, val) {
            gForces[index] = val / 9.81;
        });
    
    comes directly from the "gForcesDebug" app.

    I am sure this is painfully obvious to people who are more experienced with UI app making, but I can not figure it out.

    Thanks for your help.
     
    #1 Galahir950, Oct 15, 2014
    Last edited: Oct 15, 2014
  2. theshark

    theshark
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    137
    The gForces variable is a object. If you just try to show it it will be converted to a string which looks like this: "[object]".
    the last 4 chars of it is "ect]", which is what's shown in the app.
    What exactly do you want to show in the app?
     
  3. Galahir950

    Galahir950
    Expand Collapse

    Joined:
    Oct 11, 2014
    Messages:
    20
    Before I did anything else, I wanted to have it display the number that is being visualized in gForcesDebug.* How can I get the variable that the gForceDebug is using?

    *(a spedometer for G-Forces)
     
    #3 Galahir950, Oct 16, 2014
    Last edited: Oct 17, 2014
  4. theshark

    theshark
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    137
    the current gForce is accesible with
    gForces.gx and gForces.gy
    if you want applied smoothing, so it doesn't look as jerky, you can use
    gForces.gx2 and gForces.gy2
     
  5. Galahir950

    Galahir950
    Expand Collapse

    Joined:
    Oct 11, 2014
    Messages:
    20
    Thank you, this helped me very much. Is there anything that I have to do with the implementation to get it to act like I want it to? How many Javascript functions are implemented, is "setInterval" implemented? Do you have any idea why
    HTML:
    var previous = 1;
    shows up as NaN?
     
    #5 Galahir950, Oct 17, 2014
    Last edited: Oct 18, 2014
  6. theshark

    theshark
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    137
    The gui is basically a browser rendered ingame so every function a normal browser has could be used. But the updatemethod gets called by the game every frame, so there's no need for a own interval to redraw things (if that's what you needed it for).
    For the other problem: do you have some code for me i could test?
     
  7. Galahir950

    Galahir950
    Expand Collapse

    Joined:
    Oct 11, 2014
    Messages:
    20
    This is my app
    http://www.beamng.com/attachment.php?attachmentid=44421&d=1413590153

    I am debating whether I want to use an "if (pRevious > gForcesRound+2)" statement, logging at intervals of 1-2 seconds, or a combination of both.

    Is there any part of a stream that allows me to call the time in game or the time since you started the level?

    Have you implemented rotation G-Forces?
     
    #7 Galahir950, Oct 18, 2014
    Last edited: Oct 18, 2014
  8. theshark

    theshark
    Expand Collapse

    Joined:
    Aug 5, 2012
    Messages:
    137
    I don't think rotational gforces exist actually.

    I looked into your app and it has some problems:

    Code:
    gForcesList.prototype.setup = function(){
    	var pRevious = 1;
    };
    You define a local variable here, so as soon as you leave this function it won't exist anymore.
    just define it as
    Code:
    gForcesList.prototype.setup = function(){
    	this.pRevious = 1;
    };
    that way it will be accessible inthe whole app without polluting the global scope.

    You should define
    Code:
    function appendToTableG (gdata) { [...] }
    as
    Code:
    gForcesList.prototype.appendToTableG = function (gdata) { [...] }
    so its part of your app and doesn't pollute the global scope.

    Code:
    $('#gtable tr:first')
    you shouldn't use id's, this can lead to problems if someone else uses the same id or someone spawns your app twice. Just save a reference to it in the setupmethod like
    Code:
    this.tbody = this.tableG.find('tbody')
    and use that.

    Code:
    	var gForcesFull = ((gForces.gx+gForces.gy+gForces.gz));
    You may want to use the pythagorean theorem to correctly calculate the combined force.

    Code:
    	var pRevious = (Math.abs(gForcesRound));
    here you redefine the pRevious variable. Even if the other definition worked, it would be overridden here.

    I hope that helps :)
     
  9. Galahir950

    Galahir950
    Expand Collapse

    Joined:
    Oct 11, 2014
    Messages:
    20
    Thank you, this will be very helpful.

    I can't seem to remember where I got the concept from.
     
  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