Discuss Scratch

Happyman555
Scratcher
38 posts

Custom Blocks and Lists: Button animation errors

(PS: Sorry if this isn't written very well, all the information is in the project and describes it clearer)

I'm currently working on a new game, along with a simple and cleaner UI, which requires a Custom Block for making these buttons. Basically, these buttons are just clones and all fit into one sprite. However, whenever I add any more characters to my list after my Costume Name Variable (for the custom block), it glitches out and makes it unusable. I've tried many things such as: changing the digits, changing the way the code manages costumes and removing certain parts of the code (like the animation, which I'm pretty sure is the reason why it doesn't work). I know that the cause of the bug is from the Costume Name Variable (for the custom block) and all the Switch Costumes To blocks. The variables all come out the same value no matter what I try and I've been unable to find a fix…

In the project, I've written detailed comments to show how it works and what the problem is further, so I suggest you read this and the comments. :]

https://scratch.mit.edu/projects/888665045/
bob978321
Scratcher
78 posts

Custom Blocks and Lists: Button animation errors

Holy Moly! You wrote an essay!
Sorry if I don't understand the problem, but wouldn't it be a lot easier if you made separate sprites for all the buttons?
Happyman555
Scratcher
38 posts

Custom Blocks and Lists: Button animation errors

Sorry for the late reply (you replied at 2am for me lol)!

It probably *would* be easier, but I'm wanting to try to make a new system to make it cleaner and simpler for myself

Last edited by Happyman555 (Sept. 3, 2023 10:31:15)

Link2358
Scratcher
100+ posts

Custom Blocks and Lists: Button animation errors

How about instead of storing all the values of a button in one item, you store all of the values in different items of the list.

This removes the necessity of predictable string lengths.
To get a value, you would need a button_i variable, and everytime a new button is added, the variable is increase by 1, and added to the start of the added data like this:


The reason why there is a “#” before the number is because it will make it easier to look up the item number using this block:
(item # of (join [#](button_i)) in [Buttons v] ::list)
This makes deleting buttons and looking up values much easier.

To get data from a specific button_i, you would use the following code:
set [base v] to (item # of (join [#](button_i)) in [Buttons v] ::list)
(item ((base) + [**]) of [Buttons v]) //** The amount of items down from the # + number
//examples
(item ((base) + [1]) of [Buttons v]) // X pos
(item ((base) + [2]) of [Buttons v]) // Y pos
(item ((base) + [4]) of [Buttons v]) // Size
Happyman555
Scratcher
38 posts

Custom Blocks and Lists: Button animation errors

Link2358 wrote:

How about instead of storing all the values of a button in one item, you store all of the values in different items of the list.

This removes the necessity of predictable string lengths.
To get a value, you would need a button_i variable, and everytime a new button is added, the variable is increase by 1, and added to the start of the added data like this:


The reason why there is a “#” before the number is because it will make it easier to look up the item number using this block:
(item # of (join [#](button_i)) in [Buttons v] ::list)
This makes deleting buttons and looking up values much easier.

To get data from a specific button_i, you would use the following code:
set [base v] to (item # of (join [#](button_i)) in [Buttons v] ::list)
(item ((base) + [**]) of [Buttons v]) //** The amount of items down from the # + number
//examples
(item ((base) + [1]) of [Buttons v]) // X pos
(item ((base) + [2]) of [Buttons v]) // Y pos
(item ((base) + [4]) of [Buttons v]) // Size

Thank you SOOO MUCH!!! :]

Last edited by Happyman555 (Sept. 3, 2023 13:33:27)

Powered by DjangoBB