AlanDeSmet / human-resource-machine-viewer

Javascript to render Human Resource Machine programs similar to the original game.
GNU General Public License v3.0
9 stars 2 forks source link

TypeError: this.line_to_row is undefined #5

Closed caco3 closed 8 years ago

caco3 commented 8 years ago

Hi, thank you very much for your cool viewer. I am trying to implement it into my own PHP based interpreter. Now I wanted to highlight the active line, but I get the following error: TypeError: this.line_to_row is undefined this.active_row = this.line_to_row[line_num];

What am I doing wrong? This is the code I have:

<html>
<link href="human-resource-machine-viewer/hrm.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Ubuntu+Mono' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js"></script>
<script src="human-resource-machine-viewer/pako_inflate.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="human-resource-machine-viewer/hrm.js"></script>
</body>

    <div class="hrmcode" id="code">Loading...</div>

    <script>
        var hrmv;
        function fonts_loaded() {
                hrmv = new HRMViewer('code', 'asm/program.asm');                
                hrmv.setActiveLine(5);
        }
        WebFont.load({
                google: { families: ['Passion One'] },
                active: fonts_loaded,
                inactive: fonts_loaded,
        });
    </script>
</body>
</html>
caco3 commented 8 years ago

And when I try to run the jump update command hrmv.updateJumpArrows();, I also get errors: TypeError: this.root is undefined var table_width = this.root.outerWidth();

sixlettervariables commented 8 years ago

As you're downloading the code from an external location, when hrmv.setActiveLine is called there are no lines yet to make active as there is no code (the AJAX request is kicked off in the background so setActiveLine is called before it completes). I suggest doing the downloading yourself:

        var hrmv;
        function fonts_loaded() {
            function showCode(source) {
                hrmv = new HRMViewer('code', source);                
                hrmv.setActiveLine(5);
            }

            // download the code ourselves so we can trigger the active line change
            $.ajax({
                url: 'asm/program.asm',
                success: showCode,
                dataType: 'text'
            });
        }
        WebFont.load({
                google: { families: ['Passion One'] },
                active: fonts_loaded,
                inactive: fonts_loaded,
        });
caco3 commented 8 years ago

Thank you very much for your quick response!