Hi,
What I want to do using processing 3.x with java:
Basically read all variable values of a class, but accessing them indirectly by a string.
e.g.
class book {
String title;
int catalogue;
String author;
}
...
books[0].title = "test";
books[0].catalogue = 100;
books[0].author = "alpha";
books[1].title = "more testing";
books[1].catalogue = 200;
books[1].author = "beta";
books[2].title = "even more testing";
books[2].catalogue = 300;
books[2].author = "gamma";
I would like to have a string list or similar where the entries are “title”,“catalogue”,“author”…
So, rather than:
savefiledata = books[0].title
something by way of:
savefiledata = books[0].<insert string value here>
The class I have created a lot more than 3 attributes, and I don’t want to have to manually keep track of them all when I add/change/delete them. It’s for a game where I’m trying to create a savegame file by reading all the classes/values etc etc
I’ve done a bit of searching and it seems that it may not be possible, I have tried using a hashmap but can’t quite figure out if it would be useful or not.
Please don’t tell me the only way is to do it manually haha
Thanks in advance for any replies
Cheers,
Keith