Error reading a table

edited February 2017 in Questions about Code

Hey,

I was working on a program inspired by emily xie, a rain of character going down, back and force. The code is under p5 but i wanted to do it with processing. So I've done this :

int letterSize = 24; 
int staKata = unhex("30A1"); 
int stoKata = unhex("30FA");

Table kataTable;

void setup() {
  //Set the font. This way you can display special character.
  PFont font = createFont("ufonts.com_arial-unicode-ms.ttf", 64);
  textFont(font);
  kataTable = loadTable("katakana.csv", "header"); //Load the katakana table csv file to get the decimal/hexadecimal value of the characters
  size(720, 480);
  background(0);

  println("Start:" + unhex("30A1"));
  println("End:" + unhex("30FA"));
}

void draw() {
  background(0);
  textSize(letterSize);
  fill(0, 255, 130);
  //text(new String (Character.toChars(staKata)), width/2, height/2);
}

I load a font to have katakana symbols display on the screen. I just wanted some, that are included in the Arial Unicode MS font so i did a csv file with the corresponding character i want with their hexadecimal value. But i get an error on line 0, I don't really understand why. Here is an exemple of the csv file :

id, integer, hexadecimal, pronounciation
1,   12450,        30A2, "A"
2,   12452,        30A4, "I"
3,   12454,        30A6, "U"
Tagged:

Answers

  • But i get an error on line 0, I don't really understand why.

    Specifically, what error message do you get? What do you mean "on line 0" -- are you describing the error in your program code, or in loading the data?

  • I get a log on the console "Error reading table on line 0"

  • I wonder whether spaces are allowed among commas inside a ".csv" file. :-/

  • if this is it BRUHH @-)

  • NO ! Bullshit why is the world so mean !!

    Thats awesome it's working without the space. :(( :)

  • If you find it's not so pretty anymore w/o spaces, why not converting your ".csv" file to ".tsv" instead?

  • edited February 2017

    @Arma --

    Alternately, if you want to or need to keep the spaces in your original data file, you could have your sketch dynamically create a new file with no spaces, then load that. For example, in setup():

    1. load katakana.csv with loadStrings()
    2. split() on ,
    3. trim() each member to remove extra spaces
    4. save to katakana-nospaces.csv
    5. load katakana-nospaces.csv with loadTable()

    In this way, you can use spaces however you like in source data and still have a clean csv each time it is loaded (although it is surprising that spaces cause a problem for loadTable).

  • @GoToLoop I did think to use tsv but i don't know how they works.

    @jeremydouglass I already convert my file with no spaces, so yeah it's a good idea i'll use it another time. And I agree, thinking that spaces cause problems with loadTable is really weird.

  • I did think to use TSV but i don't know how they works.

    https://en.Wikipedia.org/wiki/Tab-separated_values

    The T in TSV stands for Tab. In order to convert CSV to TSV, simply replace all , w/ \t. ;)

Sign In or Register to comment.