[Help] Function called over 500 times even though it should only be called 80


I’m trying to make a function that draws 80 drawboxes. However it gives me an error and says that it got called over 500 times. Any help is appreciated.

Hey there, your code is stuck in an endless loop. Grasshopper limits the total number of function calls on the call stack to 500 to prevent these endless loops from crashing the app.

You have 2 variables declared that are both named Boxes, when you only want 1. Change the line var Boxes = Boxes++ to just Boxes++

Also, keep in mind that each time you call the Draw() function, you’re actually making 8 function calls:

1st, you’re calling Draw()
2nd, Draw() calls drawBoxes() with the argument 'rbrgrb'
3rd, drawBoxes() calls drawBox() with the argument 'r'
4th, drawBoxes() calls drawBox() with the argument 'b'
5th, drawBoxes() calls drawBox() with the argument 'r'
6th, drawBoxes() calls drawBox() with the argument 'g'
7th, drawBoxes() calls drawBox() with the argument 'r'
8th, drawBoxes() calls drawBox() with the argument 'b'.

This means that if you want to call Draw() 80 times, the call stack has 640 function calls on it, which exceeds the app’s 500 function call limit. Try changing the string in drawBoxes() to something shorter, like 'rbr'.

I hope that makes sense! Let me know if you have any questions.
Ben

1 Like

I see. That worked, thank you very much!

1 Like