So to summarize the issue at hand, I created an essential custom block extension for an upcoming game. And the blocks are just fine.
Blocks
Extension Code
//% weight=99 color="#FFB836" icon="\uf035"
//% block="Literals"
namespace literals {
//% block="id $newid name $newname image $newimg"
//% newimg.shadow=dialog_image_picker
export function setPlayerData(newid: string, newname: string, newimg: Image): any {
const objLiteral = {
id: newid,
name: newname,
image: newimg
}
return objLiteral
}
//% block="id $newid background image $newimg"
//% newimg.shadow=dialog_image_picker
export function setPlayerBackgroundData(newid: string, newimg: Image): any {
const objLiteral = {
id: newid,
image: newimg
}
return objLiteral
}
}
I then implemented it into my code via JavaScript. Now in the JavaScript client, everything functions smoothly.
let PlayerList: any[] = [
literals.setPlayerData("bon", "Bon", assets.image`myImage`)
]
An implementation example is this code sample:
let selectedPlayer = PlayerList.find(player => player.name === "Bon")
However when switching to the Blocks client, that’s when issues begin.
Issue
When switching to Blocks, the array type changes to number:
let PlayerList: number[] = [literals.setPlayerData("bon", "Bon", assets.image`myImage`)]
// Or if I move things around for the sake of aesthetics...
let PlayerList: number[] = [
literals.setPlayerData("bon", "Bon", assets.image`myImage`)
]
Now this seemingly automatic change obviously causes a plethora of errors:
Any help is appreciated, my goal is to keep the code adjusted at an ‘any type array’.