[extension] better-sprite-data

Ever wanted to have functions in the data of your sprite? functions that have parameters?

well, this extension adds exactly that!

This took roughly 20 minutes to make, and should be simple to use. For help using the extention, if you copy-paste this code into the js editor in your project, you can see how to use it in blocks.

8 Likes

*instantly bookmarks topic*

@Soleb244

2 Likes

@AlexK can you edit "function’ into “extension”?

Ahhh. For a second, I thought this was @richard’s Improved Sprite Data function still, until I realized it was only meant for data-functions that accept sprite as parameters only. Good stuff!!!

The only thing I find interesting/hard to understand, is the parameter take in, since it shows only shows one reporter parameter, and could get kinda confusing since some would think there is only one parameter? Unless, you explained it or “it” explained itself with the array when you use the run function block.

2 Likes

Woah! How do I use this? I see I can put a function as a sprite data but how do I set and pass parameters? :thinking:

1 Like

Yup!

3 Likes

Bro predicted it was alexk approving posts or either just said alexk for the love of the game

since the parameter is an array, it allows it to be like

mySprite.runDataFunction("testFunc", [0, "hello", mySprite, myTilemap])

and that would be mostly the same as

mySprite.testFunc(0, "hello", mySprite, myTilemap)

to factually get said value, you do:

mySprite.setDataFunction("move", function (p: any[]) {
    mySprite.x += p[0]
    mySprite.y += p[1]
})

Basically, the array is what allows multiple parameters. it can seem confusing at first, but it allows any function. (that doesnt return a value, but I have an idea for that)

2 Likes

the parameter is an array, so you can have pretty much any mount of parameters, like this:

2 Likes

Ahh I understand in javascript, but what about blocks? It’s just a blank ‘parameters’ variable for me

2 Likes

in blocks, you might need to update the extension for it to be accurate.

Speaking of update…

You can now return values!

in this update, 2 blocks were added:

What do they do? Its pretty simple, the [return (array of ...)] is the return block. It returns a value. the (sprite function last returned) will contain the data that was lat returned. You can see the 2 blocks in action here:

@teal256, I saw that you also wanted this, so here!

3 Likes