Jump to content

TypeScript Array indexing


c023-dev
 Share

Recommended Posts

Hi,

 

I was looking at this example:

 

http://examples.phaser.io/_site/view_lite.html?d=text&f=kern+of+duty.js&t=kern%20of%20duty

 

and have problems on working with the array in Typescript like this:

module DZIntro {    export class EndGame extends Phaser.State {        index = 0;        line = '';        font_sml: Phaser.RetroFont;        content:Array<string> = [        " ",        "THANK YOU FOR PLAYING",        "a phaser production",        " ",        "Kern of Duty",        " ",        "directed by rich davey",        "rendering by mat groves",        "    ",        "03:45, November 4th, 2014",        "somewhere in the north pacific",        "mission control bravo ...",        ];        create() {            this.font_sml = this.game.add.retroFont('fnt10w12h', 10, 12, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ!?: 0123456789', 10, 0, 0);            this.font_sml.multiLine = true;            this.font_sml.customSpacingY = 2;            this.font_sml.customSpacingX = 1;            this.font_sml.setFixedWidth(400, 'center');            this.font_sml.text = '!DevZoo!';            this.game.add.image(0, 80, this.font_sml);        }        update() {        }                updateLine() {        if (this.line.length < this.content[index].length) {            this.line = this.content[index].substr(0, this.line.length + 1);            // text.text = line;            this.font_sml.setText(this.line);        }        else {            //  Wait 2 seconds then start a new line            game.time.events.add(Phaser.Timer.SECOND * 2, nextLine, this);        }    }    nextLine() {        index++;        if (index < content.length) {            line = '';            game.time.events.repeat(80, content[index].length + 1, updateLine, this);        }    }    }}  

The:

 

this.line.length < this.content[index].length

 

tells me:

value of type 'string[]' is not indexable by type 'any'

 

And I guess this is something syntax related that I don't quite understand yet? Since further typing the variable (content:Array<string>) didn't help =/

Any ideas?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...