Game crashing when giving arrays to function



  • Firstly, I'm sorry if this is more of just a haxe question.

    So I am reading a text file, and then passing the lines to a two dimensional array. Then I give the array as an argument to a function. However, the game crashes as soon as I do it, and it doesn't give any error messages.

    The strange part is that if i declare the array in code, it works just fine.

    I would really appreciate help with this, I'm quite confused.

    Here's the code:

    //constructor
    
    timelineFile = Assets.getText(file);
    timelineArray = timelineFile.split('#');
    	
    timelineData = new Array();
    	
    for (i in 0...timelineArray.length)
    {
    timelineData[i] = timelineArray[i].split('\n');
    }
    
    //update
    
    var time = Std.parseFloat(timelineData[readTimePos][1]);
    var func = Std.parseInt(timelineData[readTimePos][2]);
    		
    for (i in 3...timelineData[readTimePos].length-1)
    {
    arguments[i - 3] = Std.parseInt(timelineData[readTimePos][i]);
    }
    		
    if (timelineData[readTimePos][1] != endchar)
    {
    LevelMethods.method[func](arguments); //this causes the crash
    currentMilestone = time;
    }


  • Use trace() to output intermediate values of variables before crash to console.
    Also try using explicit types like Array<Array<String>> instead of Array. The compiler may then give you some insights



  • The reason I wasn't using traces was because the game just froze, and didn't output the traces.

    Anyways I fixed the problem. I had written 1 instead of 0 in the .txt file O.o



  • If it froze before traces, you could put traces earlier.


Log in to reply