Microsoft MakeCode

string.indexOf(needle, fromIndex) not working on HW

Need some verification from my hardware experts before I file a bug report.

I’m writing a text-wrapping routine for a text adventure that I’m writing. :smiley: I’m running into a problem with string.indexOf(needle, fromIndex) when running on hardware. Code below; URL for a shared project is at the end if that’s easier.

//                      0         1         2         3
//                      0123456789012345678901234567890
let myString: string = 'Well, hello there! How are you?'
let previousSpace: number = 0
let nextSpace: number = myString.indexOf(' ', previousSpace + 1)
let round: number = 0
while (nextSpace !== -1) {
    game.showLongText('Round: ' + round +
        ' previousSpace: ' + previousSpace +
        ' nextSpace: ' + nextSpace,
        DialogLayout.Bottom)
    previousSpace = nextSpace
    nextSpace = myString.indexOf(' ', previousSpace + 1)
    round++
}   // while (nextSpace)
game.showLongText('Final round: ' + round +
    ' previousSpace: ' + previousSpace +
    ' nextSpace: ' + nextSpace,
    DialogLayout.Bottom)

In the browser simulator, it runs fine, ending after five rounds and finding all of the spaces in the string. On my BrainPad Arcade, though, it gets stuck on the first space. It seems to be ignoring the second parameter in the method call. Same issue on beta.

Can I get confirmation that others are experiencing the same thing? MakeCode devs: Let me know if you need me to file a bug report and, if so, against which repository (arcade, pxt-common, pxt, or elsewhere).

Thanks!

Yup, seems to be ignoring that besides bounds checking here. If you could file a quick issue and reference this post I’ll fix it~

1 Like

Yup; I’m on it. Thanks, Joey (@jwunderl)!

P.S. I filed the issue against pxt-arcade since I don’t seem to have permission to file issues on pxt-common-packages.

Oh, forgot to respond to that - it’s generally better to file bugs against the target (in this case pxt-arcade), as that’s where we primarily check while triaging bugs for releases - bugs are turned off in common packages completely, and we typically avoid putting them in pxt unless they are unrelated to specific targets so that we don’t miss them when preparing for releases.

Also, you can always post things that seem like bugs or behave weirdly as issues on github - even if they’re ‘working as intended’, it’s useful to see points where things aren’t working properly for users, and it’s often easier to track these bugs / have people pile on there.

1 Like

Excellent; thanks, Joey. I wasn’t sure how “conversational” the Issues log was for the PXT repos in GitHub. I’ll use that from now on for these types of things, rather than cluttering up the forum. :smile: