Hello; new here.
I have no idea what part of this is breaking. I have tried to reduce this as best as I can to a minimal example.
I have a class defined in a separate tab which is meant to represent something like a basic terminal or console output screen. This class has its own PGraphics instance to which all the characters in the terminal should be written when an update is needed. Then the terminal should be output with a call to consoleRoot.show() in my main tab.
The line that causes my array index error is module.py:26. If I comment out this line, save, and run, there is no error. I have already tried replacing the arguments to text() with constants rather than looking up a value in a 2-dimensional list.
Main tab:
import random as rng
from module import Console
consoleRoot = None
def setup():
global consoleRoot
size(800, 600)
consoleRoot = Console(100,100)
frameRate(999)
def draw():
global consoleRoot
consoleRoot.update()
consoleRoot.show()
consoleRoot.set(rng.randint(0,99), rng.randint(0,99), rng.choice('abcdefghijklmnopqrstuvwxyz'))
module.py:
tileSize = 16
class Console:
def __init__(self, w, h):
self.width = w
self.height = h
self.graphics = createGraphics(w * tileSize, h * tileSize)
self.graphics.beginDraw()
self.graphics.textAlign(CENTER, CENTER)
self.graphics.textSize(12)
self.graphics.background(0)
self.graphics.endDraw()
self.character = [[' ' for i in range(h)] for j in range(w)]
self._update = []
def set(self, x, y, character):
self.character[x][y] = character
self._update.append((x,y))
def update(self):
if len(self._update) == 0:
return
self.graphics.beginDraw()
for i in self._update:
x, y = i
self.graphics.rect(x * tileSize, y * tileSize, tileSize - 1, tileSize - 1)
self.graphics.fill(224)
self.graphics.text(self.character[x][y], int(x * tileSize), int(y * tileSize), int(tileSize), int(tileSize))
self.graphics.fill(0)
self.graphics.endDraw()
del self._update[:]
def show(self):
image(self.graphics, 0, 0)
EDIT: To be clear (because I removed a line somewhere and confused my line numbers), the line that causes the error is in module.py and reads:
self.graphics.text(self.character[x][y], int(x * tileSize), int(y * tileSize), int(tileSize), int(tileSize))