Discuss Scratch

no_idea63
Scratcher
27 posts

Why are my variables glitching out?

The project I am working on has a strange glitch when you purchase a certain upgrade, the variables glitch out and usually take double of what was intended, I have reviewed the code multiple times and cannot find anything wrong with my code. Can somebody help me?


Project: https://scratch.mit.edu/projects/497334020/
Uviferous
Scratcher
100+ posts

Why are my variables glitching out?

I'll check the code and see what's happening.
Uviferous
Scratcher
100+ posts

Why are my variables glitching out?

no_idea63 wrote:

The project I am working on has a strange glitch when you purchase a certain upgrade, the variables glitch out and usually take double of what was intended, I have reviewed the code multiple times and cannot find anything wrong with my code. Can somebody help me?


Project: https://scratch.mit.edu/projects/497334020/

try rescripting the code that subtracts from the money variable when you purchase the upgrade. that might help. and make sure the upgrade isn't being purchased twice.
no_idea63
Scratcher
27 posts

Why are my variables glitching out?

Uviferous wrote:

no_idea63 wrote:

The project I am working on has a strange glitch when you purchase a certain upgrade, the variables glitch out and usually take double of what was intended, I have reviewed the code multiple times and cannot find anything wrong with my code. Can somebody help me?


Project: https://scratch.mit.edu/projects/497334020/

try rescripting the code that subtracts from the money variable when you purchase the upgrade. that might help. and make sure the upgrade isn't being purchased twice.

I made it so it now subtracts the amount i want from the money, made sure there were no repeats of the code, it is only purchasing it once, and it still seems to take extra money starting at the third upgrade and going on.
awesome-llama
Scratcher
1000+ posts

Why are my variables glitching out?



This script is buying the lower upgrades plus the one you are supposed to buy. It's logic is not right. If I try to buy level 3, then it will buy level 2 and then level 3, even though level 2 was already bought before.



In my opinion, the way you scripted it could be way better, so I actually recommend doing it a different way. It'll be much easier to edit and glitches will be harder to create.
One of the major issues which you might have alredy experienced is the many variables you have to create just for a single upgrade. It can be done with just 3 and not 8. It's also only 1 script and does not requre broadcasts.

when this sprite clicked
if <<(upgrade level) < [5]> and <not <(money) < (cost)>>> then
change [money v] by ((0) - (cost)) // subtract money
if <(upgrade level) = [0]> then
set [spawn chance 2 v] to [13]
set [cost v] to [70]
else
if <(upgrade level) = [1]> then
set [spawn chance 2 v] to [10]
set [cost v] to [150]
else
if <(upgrade level) = [2]> then
set [spawn chance 2 v] to [8]
set [cost v] to [250]
else
if <(upgrade level) = [3]> then
set [spawn chance 2 v] to [4]
set [cost v] to [350]
else
if <(upgrade level) = [4]> then
set [spawn chance 2 v] to [1]
set [cost v] to [] // max level, cost doesn't matter
hide variable [cost v]
hide variable [upgrade level v]
switch costume to [max level v]
end
end
end
end
end
change [upgrade level v] by (1)
end
no_idea63
Scratcher
27 posts

Why are my variables glitching out?

Oh my goodness thank you so much!

and yeah, i know my coding sucks lol
no_idea63
Scratcher
27 posts

Why are my variables glitching out?

k, i implemented the code..

and as far as i know,it works! thank you!

Powered by DjangoBB