Discuss Scratch

Andyrew52
Scratcher
2 posts

My variable won't change!

No longer a problem. Thanks so much, deck26

Please help, I am trying to change my variable but it always stays the same no matter what I try.

This is my project:
https://scratch.mit.edu/projects/226108039/ (currently working on it so it is not up yet)

This is what the code looks like:
when I start as a clone
game stuff
if <touching color [#FFC7ED]> then
change (No. Left) by (1)
if <(No. Left) = [0]> then
change (Level) by (1)
end
delete this clone

Last edited by Andyrew52 (June 5, 2018 20:50:02)

deck26
Scratcher
1000+ posts

My variable won't change!

Do yourself a big favour and look at the platformer tutorial by @griffpatch_tutor. that script with multiple if touching colour/change y by 1 blocks appears regularly here as a problem.

Don't switch backdrop in a forever loop - you're just giving Scratch extra work to do. Just use wait until not backdrop# = level.

Your main problem, I suspect, is that NoLeft is a local variable so each clone has its own copy. So if a clone changes the value the sprite won't see that change - it has to be a global (all sprites) variable for that to work.

Happysoul05
Scratcher
100+ posts

My variable won't change!

Check the variable you want to change (like levels) is for one sprite or all sprites.
Andyrew52
Scratcher
2 posts

My variable won't change!

deck26 wrote:

Do yourself a big favour and look at the platformer tutorial by @griffpatch_tutor. that script with multiple if touching colour/change y by 1 blocks appears regularly here as a problem.

Don't switch backdrop in a forever loop - you're just giving Scratch extra work to do. Just use wait until not backdrop# = level.

Your main problem, I suspect, is that NoLeft is a local variable so each clone has its own copy. So if a clone changes the value the sprite won't see that change - it has to be a global (all sprites) variable for that to work.


Thanks so much deck26 it works now!!
nwibo0
Scratcher
4 posts

My variable won't change!

my varible y keeps on mis funtioning
deck26
Scratcher
1000+ posts

My variable won't change!

nwibo0 wrote:

my varible y keeps on mis funtioning
Please create your own new topic rather than necroposting.
codingGP
New Scratcher
7 posts

My variable won't change!

My variable is not changing to .I stayed a hour to fix it and still not working…

deck26
Scratcher
1000+ posts

My variable won't change!

codingGP wrote:

My variable is not changing to .I stayed a hour to fix it and still not working…

Please create your own new topic. Share and identify the project and give a bit more infomation.
nwibo0
Scratcher
4 posts

My variable won't change!

hello my varible now will change
define ()
when green flag clicked
forever

end
codingGP
New Scratcher
7 posts

My variable won't change!

deck26
Scratcher
1000+ posts

My variable won't change!

codingGP wrote:

hers the project https://scratch.mit.edu/projects/400219449/
Create a new topic please.
codingGP
New Scratcher
7 posts

My variable won't change!

what do you mean in topic?
deck26
Scratcher
1000+ posts

My variable won't change!

codingGP wrote:

what do you mean in topic?
Go the top of the forum and click on New Topic. That is the best way to ask for help instead of posting on someone else's old topic as you've done. Give more details of the problem as well - which variable should be changing and isn't? What should make it change? Make it easier for those helping to directly look at the issue.
The_Imaginarium
Scratcher
1000+ posts

My variable won't change!

codingGP wrote:

what do you mean in topic?

This Problem Is Resolved.
Go To Here: https://scratch.mit.edu/discuss/7/ And Click The Blue Button At The Top Right Of The Page.

Last edited by The_Imaginarium (Aug. 29, 2020 14:33:23)

joshuaho
Scratcher
1000+ posts

My variable won't change!

deck26 wrote:

Go the top of the forum and click on New Topic. That is the best way to ask for help instead of posting on someone else's old topic as you've done. Give more details of the problem as well - which variable should be changing and isn't? What should make it change? Make it easier for those helping to directly look at the issue.
Well stated. Yes - it's always better to create your own topic for your questions rather than posting on an old one.

Powered by DjangoBB