0

I'm working on a Scratch programming game in HTML5 and JS. Let us assume that there're code-blocks(sprites) and function-blocks which one can fill in with code-blocks. And assume that i want it work recursively, i.e. one can put a function into another function or into itself as well. The idea is to program a robot for it's movement. Assume, that in the game i create function f3(x) and put en arrow-block in it. then i create function f4(x) and put f3(x) and an arrow in it. Then I put f4(f3(arrow), arrow)-block in the commando-line. Then i write some an recursive function.

RecursiveFunc: function(codeBlock) {
    For(i=0;i<commandoLine;i++){
        if(inArray(block, functions)===true){
            RecursiveFunc(commandoLine[i])}
        else{
            executeArray.push(codeBlock)
        }
    }
}

What really happens is that when the function reads f4-block, then detects f3 and executes itself and reads the arrow in f3, then it doesn't continue to read the arrow in f4(f3, arrow), as it would work like that, for example, in Python. Is it a kind of TCO-absence problem? And how can one workaround it in JavaScript?

Thanks!

James Skemp
  • 8,018
  • 9
  • 64
  • 107
  • 2
    Did you mean to tag this as Phaser instead of Scratch? – James Skemp May 23 '16 at 10:14
  • Yes, i did. And i have no idea why it changed and why it doesn't go to get back... – Nikolai Ashokus Artjomenkov May 25 '16 at 12:34
  • So `f4` is declared with one parameter (`x`), but called with two parameters (`f3(arrow)` and `arrow`)? That might explain why the second parameter is ignored. I am guessing here; the tiny bit of code you supplied, does not reveal how you implemented parameter passing. By the way, what is TCO? Total Cost of Ownership? – Ruud Helderman Jun 13 '16 at 19:22

0 Answers0