Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need help with a script that deals with variables
- COLDEX0700
-
25 posts
Need help with a script that deals with variables
I'm making a click the button sorta thing with a button, I'm trying to make it so that when the timer is at 0 to set timer to 30 and clicks to 0 and if highscore < clicks (when timer at 0) then set highscore to clicks
However, this code doesn't seem to be working
when green flag clicked
if <[Timer] < [1]> then
set [Timer] to [30]
set [Clicks] to [0]
if <[Highscore] < [Clicks]> then
set [Highscore] to [Clicks]
end
end
However, this code doesn't seem to be working
- deck26
-
1000+ posts
Need help with a script that deals with variables
You're setting clicks to 0 just before you check if highscore is less than clicks. Looks like the reset of clicks needs to move down.
- RT_Borg
-
1000+ posts
Need help with a script that deals with variables
Hi COLDEX0700,
In addition to deck26's observation about clicks…
The blocks below “when green flag clicked” probably need to be in some kind of loop. Otherwise, you're only checking a single time right at the instant the green flag is clicked.
Is that the problem, or was leaving that out just a typo writing the forum blocks?
It's usually best to share a project link to let people here give you the best help.
– RT_Borg
In addition to deck26's observation about clicks…
The blocks below “when green flag clicked” probably need to be in some kind of loop. Otherwise, you're only checking a single time right at the instant the green flag is clicked.
Is that the problem, or was leaving that out just a typo writing the forum blocks?
It's usually best to share a project link to let people here give you the best help.
How to Share a Project Link
To share a project link, click the orange “Share” button at the top of the page. Then in “See Project Page” click Copy Link near the bottom, and Copy Link again on the pop-up, and paste it in a message.
– RT_Borg
Last edited by RT_Borg (Sept. 11, 2022 11:23:38)
- COLDEX0700
-
25 posts
Need help with a script that deals with variables
Hey RT_Borg and deck26,
Here's the project link: https://scratch.mit.edu/projects/729071250/
I tried your solution, deck26, by moving set Clicks to 0 under the highscore script but that didn't work. And the timer goes into negative number.
And RT_Borg, sorry about the forever loop, it is in the original script.
Here's the project link: https://scratch.mit.edu/projects/729071250/
I tried your solution, deck26, by moving set Clicks to 0 under the highscore script but that didn't work. And the timer goes into negative number.
And RT_Borg, sorry about the forever loop, it is in the original script.
- RT_Borg
-
1000+ posts
Need help with a script that deals with variables
when @greenFlag clicked
...
forever
if <(backdrop [name v]::looks) = [click the button]> then
...
repeat until <not <(backdrop [name v]::looks) = [click the button]>>
wait (1) secs
next costume
change [Timer v] by (-1)
end
if <(Timer::variables) \< [1]> then // ------------------- This has to move inside the repeat
set [Timer v] to [30]
if <(Highscore) \< (Clicks)> then
set [Highscore v] to (Clicks)
end
set [Clicks v] to [0]
end
else
hide
end
end
when @greenFlag clicked
...
forever
if <(backdrop [name v]::looks) = [click the button]> then
...
repeat until <not <(backdrop [name v]::looks) = [click the button]>>
wait (1) secs
next costume
change [Timer v] by (-1)
if <(Timer::variables) \< [1]> then // --------------------------------------- To here
set [Timer v] to [30]
if <(Highscore) \< (Clicks)> then
set [Highscore v] to (Clicks)
end
set [Clicks v] to [0]
end
end
else
hide
end
end
– RT_Borg
Last edited by RT_Borg (Sept. 11, 2022 11:50:31)
- hiiamshrek
-
66 posts
Need help with a script that deals with variables
I'm making a click the button sorta thing with a button, I'm trying to make it so that when the timer is at 0 to set timer to 30 and clicks to 0 and if highscore < clicks (when timer at 0) then set highscore to clickswhen green flag clicked
if <[Timer] < [1]> then
set [Timer] to [30]
set [Clicks] to [0]
if <[Highscore] < [Clicks]> then
set [Highscore] to [Clicks]
end
end
However, this code doesn't seem to be working
I think I know how.
when green flag clicked
reset timer
when [timer] > (30)
if <[(Clicks)] > [(highscore)]> then
set [highscore] to (Clicks)
end
- Discussion Forums
- » Help with Scripts
-
» Need help with a script that deals with variables