Process error column 4 dont exist

I’m coding a game and using tables. I have a bunch of lines of code that could easily be placed in a table to lessen the code, even though i’m sure everything is correct it keeps giving me an error. “Column 4 dont exist.” The table has 20 columns & row 1 has 6 numbers in it.
roomT named room.csv

6,1,3,0,1,2,3,,,,,,,,,,,,,,,
9,4,10,4,5,6,7,8,9,10,,,,,,,,,,,,
12,11,20,11,12,13,14,15,16,17,18,19,20,,,,,,,,,
7,23,27,23,24,25,26,27,,,,,,,,,,,,,,
17,31,42,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,,,,
6,43,46,43,44,45,46,47,,,,,,,,,,,,,,
8,47,52,47,48,49,50,51,52,53,,,,,,,,,,,,
8,53,58,53,54,55,56,57,58,59,,,,,,,,,,,,
7,59,63,59,60,61,62,63,64,,,,,,,,,,,,,
7,64,68,64,65,66,67,68,69,,,,,,,,,,,,,
10,69,76,69,70,71,72,73,74,75,76,,,,,,,,,,,
10,77,84,77,78,79,80,81,82,83,84,85,,,,,,,,,,
7,85,89,85,86,87,88,89,90,,,,,,,,,,,,,
12,90,99,90,91,92,93,94,95,96,97,98,99,100,,,,,,,,
12,100,109,100,101,102,103,104,105,106,107,108,109,110,,,,,,,,
7,110,114,110,111,112,113,114,,,,,,,,,,,,,,
8,115,120,115,116,117,118,119,120,,,,,,,,,,,,,
7,124,128,124,125,126,127,128,,,,,,,,,,,,,,
8,129,134,129,130,131,132,133,134,,,,,,,,,,,,,

setup

Table roomT,storyT;
TableRow tr;
int minsx, maxsx;
ArrayList<Word> word = new ArrayList<Word>();
ArrayList<Room> room = new ArrayList<Room>();

void setup(){
  size(600,600);
  roomT = loadTable("room.csv");
  storyT = loadTable("word.csv","header");
  room.add(new Room(0));
}

void draw(){
  background(125,125,125);
  for (Word w: word){
    w.show();
  }
}

room

class Room{
  int num;
  
  Room(int n){
    num = n;
    tr = roomT.getRow(n);
    int tn = tr.getInt(0);
    for (int i = 3; i <= tn; i++){
      int nt = tr.getInt(i);// here the problem
      word.add(new Word(nt));
    }
  }
}

word

class Word{
  PVector pos;
  String name;
  int s;
  
  Word(int n){
    pos = new PVector(0,0);
    tr = storyT.getRow(n);
    name = tr.getString("Name");
    pos.x = tr.getFloat("X");
    pos.y = tr.getFloat("Y");
    s = tr.getInt("Size");
  }
  
  void show(){
    fill(0);
    textSize(s);
    text(name,pos.x,pos.y);
  }
}

storyT named word.csv

Name,X,Y,Size
Story Title,5,64,64
Play,5,192,64
Control,5,256,64
Score Board,5,320,64

Ive tried

void draw(){
  tr = roomT.getRow(0);
  int ts = tr.getInt(4);
  textSize(32);
  text(ts,5,32);
}

and 3 and 4 works just fine

i also tried

void setup(){
   int page = 0;
   tr = roomT.getRow(page);
  int tn = tr.getInt(0);
  int nt = tr.getInt(3);
  word.add(new Word(nt));
  nt = tr.getInt(4);
  word.add(new Word(nt));
  nt = tr.getInt(5);
  word.add(new Word(nt));
}

error on 4

Consider
for (int i = 1; i < tn+1; i++){

1 Like

Why does it work in draw but not in setup()? As can clearly see column 4 does exist just fine. && 0 is the amount of words in room, 1 is miny in the room. 2 is maxy in room, so i need to start at 3 the number of the first word in the room.
The same code in setup will fail but in draw will work

in draw works fine

Table roomT,storyT;
TableRow tr;
int minsx, maxsx;
ArrayList<Word> word = new ArrayList<Word>();
ArrayList<Room> room = new ArrayList<Room>();
int page = 0;

void setup(){
  size(600,600);
  roomT = loadTable("room.csv");
  storyT = loadTable("word.csv","header");
  //room.add(new Room(0));
}

void draw(){
  background(125,125,125);
  for (Word w: word){
    w.show();
  }
  tr = roomT.getRow(page);
  int tn = tr.getInt(0);
  for (int i = 3; i <= tn; i++){
    int nt = tr.getInt(i);
    textSize(32);
    text(nt,5,32*i);
  }
}

but i cant keep it in draw I only need the numbers once
if read the bottom parts of the post you would see column 4 does exist

1 Like

Maybe this causes the error when n==4?

1 Like

the only things called from storyT are by name & storyT wasn’t made with a fourth column so the error still makes no sense.

storyT

Name,X,Y,Size
Story Title,5,64,64
Play,5,192,64
Control,5,256,64
Score Board,5,320,64
1 Like

Story is called with row 4.

Did you try to comment this out:

?

1 Like

if the code worked how it should roomT 0,3 should return 0, which would give us. word.add(new Word(0));
which worked when i typed the number in.
0,4 would return 1 which then turns into

word.add(new Word(1));

again worked with number

0,5 would return 2 again works if i place a 2 in
0,6 would return 3 again works if place 3 in, so looks like the problem is somewhere between roomT getting the number and roomT giving the number to word. I just tried

void draw(){
  background(125,125,125);
  for (Word w: word){
    w.show();
  }
  word.add(new Word(0));
  word.add(new Word(1));
  word.add(new Word(2));
  word.add(new Word(3));
}

those work just fine but adding words every frame would soon to be disaster.
n in word is used to get the row not the column.
Guess I’ll have to long code it. Dumb thing cant even get a simple number from the table, its retarded

1 Like

You are right.

Work-around :

Just leave the data in the code and move it to a new tab

1 Like

here the numbers i need the word works fine.

Table roomT,storyT;
TableRow tr;
int minsx, maxsx;
ArrayList<Word> word = new ArrayList<Word>();
ArrayList<Room> room = new ArrayList<Room>();
int page = 0;
boolean create = false;

void setup(){
  size(600,600);
  roomT = loadTable("room.csv");
  storyT = loadTable("word.csv","header");
  //room.add(new Room(0));
}

void draw(){
  background(125,125,125);
  for (Word w: word){
    w.show();
  }
  tr = roomT.getRow(0);
  int tn = tr.getInt(0);
  for (int i = 3; i <= tn; i++){
    int nt = tr.getInt(i);
    textSize(32);
    text(nt,5,32 + (32*i));
  }
}

here me manually placing those numbers in. without the for loop

ArrayList<Room> room = new ArrayList<Room>();
int page = 0;
boolean create = false;

void setup(){
  size(600,600);
  roomT = loadTable("room.csv");
  storyT = loadTable("word.csv","header");
  //room.add(new Room(0));
  word.add(new Word(0));
  word.add(new Word(1));
  word.add(new Word(2));
  word.add(new Word(3));
}

void draw(){
  background(125,125,125);
  for (Word w: word){
    w.show();
  }
  /*
  tr = roomT.getRow(0);
  int tn = tr.getInt(0);
  for (int i = 3; i <= tn; i++){
    int nt = tr.getInt(i);
    textSize(32);
    text(nt,5,32 + (32*i));
  }
  */
}

again code works fine showing there is not really an issue so how do i get what I want?

1 Like

I can’t help you with that, sorry

Hi @ctremblay,

The issue comes from you global variable TableRow tr, which is be used in Room and Word.

TableRow tr // global

class Room{
  Room(int n){
   ...
    tr = roomT.getRow(n); // using in Room

and 

class Word{
  ...
  Word(int n){
    ...
    tr = storyT.getRow(n); // changing in Word mess up the once in Room

Cheers
— mnse

PS: So remove the global and define local TableRow’s where required …

2 Likes

it doesnt come from the global tr i use it all the time. NVM i made an easy work around not much more code

I’ve tested your initial approach and the issue is definitely the global tr. Also implemented a version without the global tr and it do exactly what it should do so far …
Try to follow your code an in the first attempt on Room the tr referring a row of roomT and after constructor call of Word it changes the reference to a row of storyT. Back in the loop it says no column 4 because storyT hasn’t a column index 4 …

Cheers
— mnse

1 Like

if was the global tr my work around wouldnt work
here what I did.

in room

tr = roomT.getRow(page);
    n1 = tr.getInt(3);
    minsx = tr.getInt(1);
    maxsx = tr.getInt(2);
    sx = minsx;
    for (int i = n1; i <= maxsx; i++){
      word.add(new Word(i));
    }

In your workaround you are not accessing the roomT in the loop again. That’s why it works …
I can only recommend that you should try to understand what your code really is doing not just believe in what it should do in your opinion… eom

1 Like

i do access roomT, it’s the first line of code. and instead of directly sending the info into the words which i’m seeing little use for. i’m placing them in variables. See here i access roomT

tr = roomT.getRow(page);

I do understand what it does

tr = roomT.getRow(page);// access roomT to get my numbers
n1 = tr.getInt(3);// set n1 so i know my lowest number
minsx = tr.getInt(1);// set minsx should be sy so know where menu color will start
maxsx = tr.getInt(2);// set maxsx so know high sx point
sx = minsx;// set sx to minsx so can do my menu
for (int i = n1; i <= maxsx; i++){// looping through lowest to highest
word.add(new Word(i));// creating the words
}

I think you not want to understand what I’m saying …
I’ve already explained above what was wrong …

and why your workaround works…

I’ll stop further discussions here. Nevertheless, I wish you all the best …

Cheers
— mnse

2 Likes