Pregunta

So on my end state I want to have the user input their initials. I have setup an array that has all the alphabet, triggers to select a letter and font_draw, but I cant seem but I get an error saying my function is not defined. Any ideas?

    userInitials: function(){
        io_clear();
        a = 0
        l[0] = " "
        l[1] = "a"
        l[2] = 'b'
        l[3] = 'c'
        l[4] = 'd'
        l[5] = 'e'
        l[6] = 'f'
        l[7] = 'g'
        l[8] = 'h'
        l[9] = 'i'
        l[10] = 'j'
        l[11] = 'k'
        l[12] = 'l'
        l[13] = 'm'
        l[14] = 'n'
        l[15] = 'o'
        l[16] = 'p'
        l[17] = 'q'
        l[18] = 'r'
        l[19] = 's'
        l[20] = 't'
        l[21] = 'u'
        l[22] = 'v'
        l[23] = 'w'
        l[24] = 'x'
        l[25] = 'y'
        l[26] = 'z'
        str = ""

        if(ig.input.pressed('up')){             
            if (a>26){
                a+= 1;
            }else{
                a = 0;
            }
        }

        if(ig.input.pressed('down')){
            if (a<0){
                a -= 1;
            }else{
                a = 26;
            }
        }

        this.font_draw(x,y,str+'['+1[a]+'] ');

        if(ig.input.pressed('space')){
            str += l[a];
        }
    },

    draw:function(){
        if(this.gameOver){
            this.font.draw(userInitials, ig.system.width/2, 95, ig.Font.ALIGN.CENTER);
    }
¿Fue útil?

Solución

When you're calling functions you want to use 'this'.

If there's no current object, 'this' refers to the global object. In a web browser, that’s ‘window’ — the top-level object, which represents the document, location, history and a few other useful properties and methods.

this’ remains the global object if you’re calling a function:

So therefore, this.userInitials() will work:

this.font.draw(this.userInitials(), ig.system.width/2, 95, ig.Font.ALIGN.CENTER);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top