Item Generator for D&D

Hello!

Since I would like to start playing D&D, and also want to make things easier for me in the long run, I’m planning on making an item creator.
The code I have so far allows me to write out an item, and save the data to a text file, for example “Rusty Sword.txt”.

Now I want to make a program that helps me to convert a batch of the previously created files into png files. But first, I’ll have to load the objects into my program. This is as far as I got:

import java.util.Date;

String path;
File[] files;
File f;
String[][] list;
int var = 0;

void setup() {
path = sketchPath();
files = listFiles(path);
for (int i = 0; i < files.length; i++) {
f = files[i];
list = new String[files.length][10];
list[i] = match(f.getName(), “.txt”);
if (list[i] != null) {
for (int b = 0; b < list.length; b++) {
list[b] = loadStrings(f.getName());
for (int a = 0; a < list[b].length; a++)if(var < files.length)println(list[b][a]);
}
}
}

exit();
}

Now, it does what is supposed to. Kind of. The main problem I’m having is that the code as it is now prints my files to the console exactly as often as I have files in my root folder. If I have three files in there, it will print my Strings five times, as it will do so for the data folder, the applet itself, and the actual text files I want to convert.

I know that this is because of my for loops being stuck inside each other, but I just can’t wrap my head around how to to it -just- once, or how to even get my code to work in any other form that what I have now.

Does anyone have any ideas? I’m looking forward to your answers.
Pstscrpt: Sorry if my formatting is off, this my first post, because I just really wanna get past this road block in my head.

I don’t think you need this line

I am not sure about this.

In one text file could be sword, magic stone and shield. It could be named itemsPlayerJohn or my items20200930

and welcome to the forum!

Great to have you here!

Here is an example

This Sketch takes all lines from all files and copies all in one array

(Remark

You can also have different items in one text file and load a specific file with a load dialog

It’s selectInput() see reference

It’s a bit tricky )

But here is the Sketch


import java.util.Date;


String[] resultList={};

void setup() {
  size(800, 800);

  String path;
  File[] files;
  File f;
  // String[][] list;
  //int var = 0;

  path = sketchPath();
  files = listFiles(path);

  for (int i = 0; i < files.length; i++) {
    f = files[i];
    String fname=f.getName(); 

    if (f != null && fname.indexOf(".txt") == fname.length()-4) {
      String[]  list2 = loadStrings(f.getName());
      resultList =  (String[]) concat(resultList, list2);
    }
  }//for

  // show result
  for (int a = 0; a < resultList.length; a++) {
    println(resultList[a]);
  }

  // exit();
  println("--- done setup()");
}

void draw() {
  background (0); 

  for (int a = 0; a < resultList.length; a++) {
    noFill(); 
    stroke(255);
    rect (66*a+20, 20, 
      50, 144);

    fill(255);
    text(resultList[a], 
      66*a+20 + 6, 20+16);
  }
}
//