Help with pixel art end math issue's

@YuHayate you can shove whatever extra properties you want into a Sprite using the sprite.data property.

For example:

console.log(sprite.data.name)     // prints "undefined"

sprite.data.name = "josephine"

console.log(sprite.data.name)     // prints "josephine"
console.log(sprite.data["name"])  // prints "josephine"

Just be aware that the sprite.data property has the any type so you need to be careful when accessing properties off of it. The compiler won’t catch any spelling or type errors

3 Likes

ya what i mean is to get the name of a sprite like

let list: any[] = []
console.log(list.name)
// returns list
1 Like

Ah, you mean getting the name of a variable as a string? We don’t support that.

If you’re just trying to check the type of something at runtime, then instanceof is good for that. For example:

function printType(arg: any) {
    if (arg instanceof Sprite) {
        console.log("Sprite")
    }
    else if (arg instanceof Array) {
        console.log("Array")
    }
    else {
        console.log("Unknown")
    }
}
3 Likes

That code will break. I’m note sure what you’re trying to do here exactly either…
Like @richard said, to assign a name to a sprite, do sprite.data.name = "name"

To retrieve it just grab sprite.data.name or sprite.data["name"]

1 Like

it was an example, what i want is to get the name of the variable like the text we use to declare set modify the variable
like if we declare a variable like let NameOfSprite = "anything"
i want a way to get the name of the sprite (in this case NameOfSprite) and return it as a string

1 Like

That’s unfortunately not possible. Could you provide a use-case scenario where you would need this?

2 Likes

well if i want to use throw "" with a function a make to replace all <‘number’> to a string in a array at index ‘number’, i wanted to get a sprite name to make the error look more clear

1 Like

You can just write “list”, it will be apparent which variable it’s referring to because it will highlight the line/block in question

1 Like

hey guys do you thing this color is too bright?
image

3 Likes

“Becomes blind”. Yes indeed it is too bright

6 Likes

Yeah definitely

2 Likes

XD, ok its to bright, got it

2 Likes

hey @richard. is there a way to add library’s to makecode arcade?

2 Likes

@YuHayate do you mean a specific javascript library?

extensions are themselves libraries. however, if you’re trying to use some 3rd party non-makecode library it will really depend on the implementation as to whether it will work or not. most likely it will not work unless the library is very very simple.

5 Likes

alright thanks

2 Likes

hey @richard! i was making a extension and i tried to make a total run time function using settings.
but instead of keeping track of the total time like in This, so in that example i use the better settings extension here.
but if i use setting. from the javascript editor it just makes makecode not work? it just makes the editors not work or take 5 minutes to load

the code im using in my extension

settings.writeNumber("StartRunTime", settings.readNumber("TotalRunTime"))
let TotalRunTime = 0

game.onUpdate(function() {
        TotalRunTime = game.runtime() + settings.readNumber("StartRunTime");
        settings.writeNumber("TotalRunTime", TotalRunTime);
})
2 Likes

@YuHayate that code works fine for me… Can you share the whole project?

3 Likes

ok… i wanted to finish it first but sure

i took the code out to work on this project and now it doesnt bug out it just doesnt work

2 Likes

hmmmm, yeah i’m not really sure what’s going on here! that share link works fine for me.

3 Likes

the console is just NaN or 0 for me

2 Likes