0

I assume that the Repeat() block in Scratch has some kind of internal counter that increments or decrements at the beginning or end of each time around the block.

Can the value of this counter be accessed in any way?

I realize this can be done to have an available counter, but I am only interested in this for potential similar implementation in a different language that I help develop.

Adám
  • 6,573
  • 20
  • 37
  • 1
    Not from within Scratch, but if you're designing a language, you of course could make it accessible. I also recommend taking a look at [Snap!](http://snap.berkeley.edu/), a language based on Scratch; specifically, import the tools library and look at the repeat block from there - it comes with a counter. – Scimonster Feb 10 '16 at 05:29

2 Answers2

1

No, but variables are your friend:

set counter to 0
repeat times
  change counter by 1
  ...
end

Should be fairly self descriptive :)

Now you don't even need to look at an "internal counter"!

Nebula
  • 6,614
  • 4
  • 20
  • 40
1

Well, sort of...

There is a block, called the foreach block, which works just like the repeat block except you can choose a variable to set the loop counter to.

It was removed from the block listing in the early Scratch 2.0 beta, and not many people know about it, but here is a working example on the Scratch website: For each v in number. Note that it doesn't use %m.list internally, so you have to change the JSON of the project with something like ScratchEdit or a text editor to pick a variable other than v.

wizzwizz4
  • 6,140
  • 2
  • 26
  • 62
  • This doesn't answer my question. It seems that the correct answer is "No, you cannot!". – Adám Feb 16 '16 at 16:19
  • @NBZ It's a repeat, just with a way to access the internal variable. I think it's pretty much the same. (But no, this doesn't *strictly* answer the question!) – wizzwizz4 Feb 16 '16 at 19:11