8000 Unexpected behavior with nested Repeat loops · Issue #645 · stevekrouse/WoofJS · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to c 10000 ontent
Unexpected behavior with nested Repeat loops #645
Open
@AndrewTalaski2996

Description

@AndrewTalaski2996

When attempting to complete the WoofJS tutorial for Wordle, I ran into an issue with nesting repeat loops.
It appears that nesting repeat loops does not create the grid of squares needed for the application.

var offset_x = 0
var offset_y = 0
repeat(6, () => {
 repeat(5, () => {
   var rect = new Rectangle()
   rect.x = -150
   rect.y = 250
   rect.width = 75
   rect.height = 75
   
   rect.x = -150 + (offset_x * 85)
   rect.y = 250 - (offset_y * 85)
   offset_x += 1
 })
 offset_x = 0
 offset_y += 1
})

The code above produces a shape like the below

Image

What is equally confusing is that using range().forEach loops works as expected.

var offset_x = 0
var offset_y = 0
range(0, 6).forEach(counter => {
  range(0, 5).forEach(counter => {
    var rect = new Rectangle()
    rect.x = -150
    rect.y = 250
    rect.width = 75
    rect.height = 75

    rect.x = -150 + (offset_x * 85)
    rect.y = 250 - (offset_y * 85)
    offset_x += 1
  })
  offset_x = 0
  offset_y += 1
})

The code above produces a proper 5x6 grid like the below

Image

I've had a few pairs of eyes look over this situation, and the best I can gather is that the slowed down nature of the repeat loop is causing this issue somehow. If the range().forEach loops work as expected, then I can only assume so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0