Discuss Scratch

TerryLeeStudio
Scratcher
100+ posts

Increment counter

Already in various programming languages as i
Working principe
1.when forever, repeat or repeat until block is started, it reset to 0
2.when the script inside them ends and the block loops, it increase by 1
3.you will only able to put this reporter to the block mentioned above and local to the block. Which means if you have 2 loops running, the counter won’t be messed up
Mock-up using scratchblocks
(loop increment :: control)
or
(times looped :: control)
There is a workaround by using a variable but just like the change block, it is common enough that it deserves it own reporter block

Last edited by TerryLeeStudio (April 7, 2023 12:02:14)

k7e
Scratcher
1000+ posts

Increment counter

That exists through hacked blocks, you can backpack it from here (look at the “Historical” sprite).
TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
k7e
Scratcher
1000+ posts

Increment counter

TerryLeeStudio
Scratcher
100+ posts

Increment counter

k7e wrote:

Duplicate.
That’s a manual counter, I want an integrated counter within loops that increase when it loops.
Like this example
define split (word) at blank
repeat (1000)
if <(letter (loop increment :: control) of (word)) = [ ]> then
add (var) to [list v]
set [var v] to [0]
else
set [var v] to (join (var) (letter (loop increment :: control) of (word))
end
end
There is workaround of these blocks, but they are used frequent enough to add them in
define split (word) at blank
set [loop increment replacement v] to [0]
repeat (1000)
if <(letter (loop increment replacement) of (word)) = [ ]> then
add (var) to [list v]
set [var v] to [0]
else
set [var v] to (join (var) (letter (loop increment replacement) of (word))
end
change [loop increment replacement v] by (1)
end
<[] = []>

Last edited by TerryLeeStudio (April 17, 2023 14:59:41)

TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
qwerty_wasd_gone
Scratcher
1000+ posts

Increment counter

Support, I don't like using variables as a workaround, this new block would save me time!

But there might be a problem, what if you put a loop inside a loop? which loop would it detect?

when green flag clicked
repeat until <(x position) = [40]>
repeat (3)
move (loop increment::control) steps
end
end

Last edited by qwerty_wasd_gone (April 18, 2023 13:05:31)

TerryLeeStudio
Scratcher
100+ posts

Increment counter

qwerty_wasd_gone wrote:

Support, I don't like using variables as a workaround, this new block would save me time!

But there might be a problem, what if you put a loop inside a loop? which loop would it detect?

when green flag clicked
repeat until <(x position) = [40]>
repeat (3)
move (loop increment::control) steps
end
end
Great question, looking for various Python document, seems like inside is more intuitive
qwerty_wasd_gone
Scratcher
1000+ posts

Increment counter

TerryLeeStudio wrote:

qwerty_wasd_gone wrote:

Support, I don't like using variables as a workaround, this new block would save me time!

But there might be a problem, what if you put a loop inside a loop? which loop would it detect?

when green flag clicked
repeat until <(x position) = [40]>
repeat (3)
move (loop increment::control) steps
end
end
Great question, looking for various Python document, seems like inside is more intuitive
what do you mean by inside?
TerryLeeStudio
Scratcher
100+ posts

Increment counter

qwerty_wasd_gone wrote:

TerryLeeStudio wrote:

qwerty_wasd_gone wrote:

Support, I don't like using variables as a workaround, this new block would save me time!

But there might be a problem, what if you put a loop inside a loop? which loop would it detect?

when green flag clicked
repeat until <(x position) = [40]>
repeat (3)
move (loop increment::control) steps
end
end
Great question, looking for various Python document, seems like inside is more intuitive
what do you mean by inside?
I mean it will move 0, 1, 2, 0, 1, 2 steps etc.
qwerty_wasd_gone
Scratcher
1000+ posts

Increment counter

TerryLeeStudio wrote:

qwerty_wasd_gone wrote:

TerryLeeStudio wrote:

qwerty_wasd_gone wrote:

Support, I don't like using variables as a workaround, this new block would save me time!

But there might be a problem, what if you put a loop inside a loop? which loop would it detect?

when green flag clicked
repeat until <(x position) = [40]>
repeat (3)
move (loop increment::control) steps
end
end
Great question, looking for various Python document, seems like inside is more intuitive
what do you mean by inside?
I mean it will move 0, 1, 2, 0, 1, 2 steps etc.
ok
TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
waitwhat2288
Scratcher
100+ posts

Increment counter

I cease to understand what's so difficult about implementing your own indexes, it's just setting the initial and how much it increments with two blocks of code and an index variable.

However, many other people and I use indexes extremely often, so it wouldn't necessarily be a waste of yet another “not used so often” reporter.

Last edited by waitwhat2288 (July 9, 2023 17:59:37)

TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
TerryLeeStudio
Scratcher
100+ posts

Increment counter

Bump
SonicFanX123_321
Scratcher
1000+ posts

Increment counter

like the 6502 asm
inc Variable
right? then you can just make a variable.

Powered by DjangoBB