Hey everybody.
I'm currently working on making a simple 2D "engine" of sorts in which I can assign certain objects to certain coordinates and it will render them out there. It's mainly to be about 2D animation and the like, but that's besides the point.
I'm working on a coordinate grid (possibly called array) which will be invisible but will be the coordinate system used to identify where objects are going to be rendered. It uses an x and y axis and I'm trying to make it so that you can choose the size of the grid so it's not misceallaneously rendering out blank space.
Heres the code I have:

import math
calculatingcoords = True
coordinates = []
xlength = 10
ylength = 10
while calculatingcoords == True:
    if xlength != 0:
        calculatingcoords.append((xlength - 1, ylength))
    if ylength != 0:
        coordinates.append((xlength, ylengt - 1))
    if ylength == 0:
        if xlength == 0:
            calculatingcoords == False

The problem I get here is that an memory error on line 10. I know a memory error is when your program runs out of RAM to run off of, but even when I replaced the xlength and ylength values with 1's, making it so that there would only be about 4 in the list, it still gets the error. I'm not sure why.
I'm willing to scrap the program as it is if there is a simpler solution, so is there a way to fix it? Or should I start all over. Thanks in advance, everybody!

You're running out of memory because calculatingcoords never becomes False, and the loop runs forever, appending more and more items to coordinates.

It would be easier if you give us an example of your expected result in the list coordinates.

Edited 1 Month Ago by Gribouillis

Well the list would contain every possible combination of all the numbers 1-10 in a tuple, so basically this:

(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0), (9, 0), (10, 0)
(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (6, 1), (7, 1), (8, 1), (9, 1), (10, 1)
(0, 2), (1, 2), (2, 2), (3, 2), (4, 2), (5, 2), (6, 2), (7, 2), (8, 2), (9, 2), (10, 2)
etc. etc.

You can get this with

coordinates = [(i, j) for j in range(11) for i in range(11)]

although many programmers would use numpy for such tasks.

I always forget about range loops, I think this would work. Thank you!

This question has already been answered. Start a new discussion instead.