Discuss Scratch

DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

Hi I'm trying to make a visual counter to display how many items you have of a certain category in your inventory, but for some reason its not displaying the last digit. As you will see in the sprite “senzubeancounter” I have set the number of senzu beans to “213”, but it only displays it as “21”. But when I press the script “when I start as a clone”, the last digit is displayed. Can anyone help me?

project link: https://scratch.mit.edu/projects/581942983

(to get to the inventory press the green flag, press space and then press inventory. then you will see what i mean. ignore any other sprites im sure the problem is with that specific sprite i mentioned above)

thanks

this is my signature.
deck26
Scratcher
1000+ posts

Help with a visual counter not displaying last digit

Initialise clone# and num to 1 instead of 0.
CoolBoy4286
Scratcher
100+ posts

Help with a visual counter not displaying last digit

DBZboy21Gaming wrote:

Hi I'm trying to make a visual counter to display how many items you have of a certain category in your inventory, but for some reason its not displaying the last digit. As you will see in the sprite “senzubeancounter” I have set the number of senzu beans to “213”, but it only displays it as “21”. But when I press the script “when I start as a clone”, the last digit is displayed. Can anyone help me?

project link: https://scratch.mit.edu/projects/581942983

(to get to the inventory press the green flag, press space and then press inventory. then you will see what i mean. ignore any other sprites im sure the problem is with that specific sprite i mentioned above)

thanks
You need to repeat length of senzubeans variable instead of reapeating length of senzubeans -1 in your senzubeancounter sprite.

01001110 01100101 01110110 01100101 01110010 00100000 01100111 01101111 01101110 01101110 01100001 00100000 01100111 01101001 01110110 01100101 00100000 01111001 01101111 01110101 00100000 01110101 01110000 if you translate this,


DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

deck26 wrote:

Initialise clone# and num to 1 instead of 0.
this didnt work, it changed the number displayed to 221 instead of 223, but thanks anyways

edit: it did work i just forgot to initialise both clone# and num, my bad. thank you for helping

Last edited by DBZboy21Gaming (Oct. 11, 2021 13:34:05)


this is my signature.
DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

CoolBoy4286 wrote:

DBZboy21Gaming wrote:

Hi I'm trying to make a visual counter to display how many items you have of a certain category in your inventory, but for some reason its not displaying the last digit. As you will see in the sprite “senzubeancounter” I have set the number of senzu beans to “213”, but it only displays it as “21”. But when I press the script “when I start as a clone”, the last digit is displayed. Can anyone help me?

project link: https://scratch.mit.edu/projects/581942983

(to get to the inventory press the green flag, press space and then press inventory. then you will see what i mean. ignore any other sprites im sure the problem is with that specific sprite i mentioned above)

thanks
You need to repeat length of senzubeans variable instead of reapeating length of senzubeans -1 in your senzubeancounter sprite.
this worked but i dont understand why. could you explain why you create 3 clones? because if you have the original sprite and 3 clones you should have 4 digits, but it only displays 3. thanks for helping me solve the problem as well

this is my signature.
CoolBoy4286
Scratcher
100+ posts

Help with a visual counter not displaying last digit

DBZboy21Gaming wrote:

CoolBoy4286 wrote:

DBZboy21Gaming wrote:

Hi I'm trying to make a visual counter to display how many items you have of a certain category in your inventory, but for some reason its not displaying the last digit. As you will see in the sprite “senzubeancounter” I have set the number of senzu beans to “213”, but it only displays it as “21”. But when I press the script “when I start as a clone”, the last digit is displayed. Can anyone help me?

project link: https://scratch.mit.edu/projects/581942983

(to get to the inventory press the green flag, press space and then press inventory. then you will see what i mean. ignore any other sprites im sure the problem is with that specific sprite i mentioned above)

thanks
You need to repeat length of senzubeans variable instead of reapeating length of senzubeans -1 in your senzubeancounter sprite.
this worked but i dont understand why. could you explain why you create 3 clones? because if you have the original sprite and 3 clones you should have 4 digits, but it only displays 3. thanks for helping me solve the problem as well
I don't remember the code but I think it was something like this:
set [ clone#] to (0)
change [ number] by (0)
repeat (length of (senzubeans)-1)
create clone of [ myself]
change [ num] by (1)
change [ clone#] by (1)
end
What this code does is after the main sprite does everything the number is set to 0 and clone# is also set to 0 meaning that the main sprit is not counted as the the first digit and the first clone is, so repeating length of that senzubeans -1 means you get 1 digit less than total, if you just show it and set the number to 1 and clone # to 1 before the repeat loop the original sprite will be counted as the first one and you'll need to repeat length of senzubeans -1, and the reason the main sprite wasn't showing was because it was being overlapped by the clones.

Last edited by CoolBoy4286 (Oct. 12, 2021 05:57:34)


01001110 01100101 01110110 01100101 01110010 00100000 01100111 01101111 01101110 01101110 01100001 00100000 01100111 01101001 01110110 01100101 00100000 01111001 01101111 01110101 00100000 01110101 01110000 if you translate this,


deck26
Scratcher
1000+ posts

Help with a visual counter not displaying last digit

It depends whether you're happy for the sprite to show the first digit or want it to only be clones. What you had was overlaying the first clone on top of the sprite and giving it the same costume. My fix made the first clone show the second digit.

If you just increase the repeat loop value it appears to fix the problem but you're still overlaying the first clone on top of the sprite.
DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

deck26 wrote:

It depends whether you're happy for the sprite to show the first digit or want it to only be clones. What you had was overlaying the first clone on top of the sprite and giving it the same costume. My fix made the first clone show the second digit.

If you just increase the repeat loop value it appears to fix the problem but you're still overlaying the first clone on top of the sprite.
that makes sense thanks

this is my signature.
DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

CoolBoy4286 wrote:

DBZboy21Gaming wrote:

CoolBoy4286 wrote:

DBZboy21Gaming wrote:

Hi I'm trying to make a visual counter to display how many items you have of a certain category in your inventory, but for some reason its not displaying the last digit. As you will see in the sprite “senzubeancounter” I have set the number of senzu beans to “213”, but it only displays it as “21”. But when I press the script “when I start as a clone”, the last digit is displayed. Can anyone help me?

project link: https://scratch.mit.edu/projects/581942983

(to get to the inventory press the green flag, press space and then press inventory. then you will see what i mean. ignore any other sprites im sure the problem is with that specific sprite i mentioned above)

thanks
You need to repeat length of senzubeans variable instead of reapeating length of senzubeans -1 in your senzubeancounter sprite.
this worked but i dont understand why. could you explain why you create 3 clones? because if you have the original sprite and 3 clones you should have 4 digits, but it only displays 3. thanks for helping me solve the problem as well
I don't remember the code but I think it was something like this:
set [ clone#] to (0)
change [ number] by (0)
repeat (length of (senzubeans)-1)
create clone of [ myself]
change [ num] by (1)
change [ clone#] by (1)
end
What this code does is after the main sprite does everything the number is set to 0 and clone# is also set to 0 meaning that the main sprit is not counted as the the first digit and the first clone is, so repeating length of that senzubeans -1 means you get 1 digit less than total, if you just show it and set the number to 1 and clone # to 1 before the repeat loop the original sprite will be counted as the first one and you'll need to repeat length of senzubeans -1, and the reason the main sprite wasn't showing was because t was hidden at that time.
i see what you mean thanks

this is my signature.
DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

Also I need a bit more help with this, its not about the original problem but its on the same topic. If you open up the project and go to “inventory” it will display random numbers (random for testing purposes), which is perfectly fine, however if you press the menu button and go into inventory again maybe 3 or 4 times, then it kinda glitches out and only displays the first digit of each number. I have literally no idea why this is happening so if anyone could help I would appreciate it thanks.

project link : https://scratch.mit.edu/projects/581942983

remember to keep going in and out of the inventory about 3 or 4 times and you will notice the glitch

this is my signature.
deck26
Scratcher
1000+ posts

Help with a visual counter not displaying last digit

You don't appear to be deleting clones. There is a 300 clone limit and clones will respond to broadcasts etc so you probably have clones creating clones and don't realise it so you hit the limit far quicker than you expect.

I would recommend creating the clones you need for the inventory at the start and just hide or show them as necessary. That tends to be more efficient than constantly creating, deleting, recreating.
DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

deck26 wrote:

You don't appear to be deleting clones. There is a 300 clone limit and clones will respond to broadcasts etc so you probably have clones creating clones and don't realise it so you hit the limit far quicker than you expect.

I would recommend creating the clones you need for the inventory at the start and just hide or show them as necessary. That tends to be more efficient than constantly creating, deleting, recreating.
oo thats an interesting idea ill try that thanks. btw is the 300 clone limit 300 clones for each sprite or 300 clones in the whole project?

this is my signature.
CoolBoy4286
Scratcher
100+ posts

Help with a visual counter not displaying last digit

DBZboy21Gaming wrote:

deck26 wrote:

You don't appear to be deleting clones. There is a 300 clone limit and clones will respond to broadcasts etc so you probably have clones creating clones and don't realise it so you hit the limit far quicker than you expect.

I would recommend creating the clones you need for the inventory at the start and just hide or show them as necessary. That tends to be more efficient than constantly creating, deleting, recreating.
oo thats an interesting idea ill try that thanks. btw is the 300 clone limit 300 clones for each sprite or 300 clones in the whole project?
300 for the entire project.

01001110 01100101 01110110 01100101 01110010 00100000 01100111 01101111 01101110 01101110 01100001 00100000 01100111 01101001 01110110 01100101 00100000 01111001 01101111 01110101 00100000 01110101 01110000 if you translate this,


CoolBoy4286
Scratcher
100+ posts

Help with a visual counter not displaying last digit

DBZboy21Gaming wrote:

CoolBoy4286 wrote:

DBZboy21Gaming wrote:

CoolBoy4286 wrote:

DBZboy21Gaming wrote:

Hi I'm trying to make a visual counter to display how many items you have of a certain category in your inventory, but for some reason its not displaying the last digit. As you will see in the sprite “senzubeancounter” I have set the number of senzu beans to “213”, but it only displays it as “21”. But when I press the script “when I start as a clone”, the last digit is displayed. Can anyone help me?

project link: https://scratch.mit.edu/projects/581942983

(to get to the inventory press the green flag, press space and then press inventory. then you will see what i mean. ignore any other sprites im sure the problem is with that specific sprite i mentioned above)

thanks
You need to repeat length of senzubeans variable instead of reapeating length of senzubeans -1 in your senzubeancounter sprite.
this worked but i dont understand why. could you explain why you create 3 clones? because if you have the original sprite and 3 clones you should have 4 digits, but it only displays 3. thanks for helping me solve the problem as well
I don't remember the code but I think it was something like this:
set [ clone#] to (0)
change [ number] by (0)
repeat (length of (senzubeans)-1)
create clone of [ myself]
change [ num] by (1)
change [ clone#] by (1)
end
What this code does is after the main sprite does everything the number is set to 0 and clone# is also set to 0 meaning that the main sprit is not counted as the the first digit and the first clone is, so repeating length of that senzubeans -1 means you get 1 digit less than total, if you just show it and set the number to 1 and clone # to 1 before the repeat loop the original sprite will be counted as the first one and you'll need to repeat length of senzubeans -1, and the reason the main sprite wasn't showing was because t was hidden at that time.
i see what you mean thanks
Np!

01001110 01100101 01110110 01100101 01110010 00100000 01100111 01101111 01101110 01101110 01100001 00100000 01100111 01101001 01110110 01100101 00100000 01111001 01101111 01110101 00100000 01110101 01110000 if you translate this,


DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

CoolBoy4286 wrote:

DBZboy21Gaming wrote:

deck26 wrote:

You don't appear to be deleting clones. There is a 300 clone limit and clones will respond to broadcasts etc so you probably have clones creating clones and don't realise it so you hit the limit far quicker than you expect.

I would recommend creating the clones you need for the inventory at the start and just hide or show them as necessary. That tends to be more efficient than constantly creating, deleting, recreating.
oo thats an interesting idea ill try that thanks. btw is the 300 clone limit 300 clones for each sprite or 300 clones in the whole project?
300 for the entire project.
cool ty

this is my signature.
DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

deck26 wrote:

You don't appear to be deleting clones. There is a 300 clone limit and clones will respond to broadcasts etc so you probably have clones creating clones and don't realise it so you hit the limit far quicker than you expect.

I would recommend creating the clones you need for the inventory at the start and just hide or show them as necessary. That tends to be more efficient than constantly creating, deleting, recreating.
what do you mean by efficient? will it make the project faster?

also if you dont mind could you help me with coding it so that it creates all the clones at the start im struggling. no problem if you cant tho dw.

i can fix the problem by deleting the clones but im worried about what you say when its less efficient

Last edited by DBZboy21Gaming (Oct. 11, 2021 15:57:47)


this is my signature.
deck26
Scratcher
1000+ posts

Help with a visual counter not displaying last digit

Efficiency shouldn't matter too much for a project like this but the general point is worth remembering and it does no harm to try to work efficiently.

You know where the clones are going to go, you can work out the maximum number you need for each position so you just create them as you would now but do it at the start and hide them - the initial costume doesn't matter. You already know how to create them!

Then, when the appropriate screen is being displayed you can broadcast to get the clones to set the right costume according to what they're representing and tell them to show. If the value is not long enough the clones that are not required can stay hidden.

I assume you're using a different sprite for each value - eg one to display senzubeans and another to display something else? It would be possible to use one sprite to do it all but would mean a bit more work.

DBZboy21Gaming
Scratcher
95 posts

Help with a visual counter not displaying last digit

deck26 wrote:

Efficiency shouldn't matter too much for a project like this but the general point is worth remembering and it does no harm to try to work efficiently.

You know where the clones are going to go, you can work out the maximum number you need for each position so you just create them as you would now but do it at the start and hide them - the initial costume doesn't matter. You already know how to create them!

Then, when the appropriate screen is being displayed you can broadcast to get the clones to set the right costume according to what they're representing and tell them to show. If the value is not long enough the clones that are not required can stay hidden.

I assume you're using a different sprite for each value - eg one to display senzubeans and another to display something else? It would be possible to use one sprite to do it all but would mean a bit more work.

ah i see what you mean thanks for the help, but i think im gonna stick to this for now. that seems to confusing at the moment, maybe ill do it once ive got the project completed, eg fighting, leveling up etc

this is my signature.

Powered by DjangoBB