Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

422
Views
How can I get a loop in setup() to reset?

I have a for loop in function setup() which I would like to reset and run again when my game resets. The purpose of resetting the loop is to get all the objects in the array back to their start position and colour, or to just create completely new objects.

function setup() {
  createCanvas(550, 550)
  for(let i = 0; i<200; i++) {
    x = random(width)
    y = -50 - 50 * i
    r = random(15,50)
    enemies[i] = new Enemy (x, y, r)
  }
}

I imagine that I won't be able to do this directly since function setup() can only run once, so is there a workaround to get the setup () for loop to reset?

Link to full code here if needed

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Move the relevant code to reset them to another function, perhaps, reset(). Then you can call reset() from setup(), and also call reset() whenever you need to reset them.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!