Hi !
I'm coding my 3rd game and I have one question :
- How to save and load int ?
I already tried to convert int to byte, save bytes, load bytes and convert to int but it doesn't work :(
How can I do?
I'm french, sorry for my bad english.
Thanks in advance.
Answers
How can I use markdown for show you an example ?
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Thanks, but how to convert Strings[] to int ?
Convert the whole Strings[] to int[] via function int().
It's also a good idea to call trim() before int() for safety:
https://Processing.org/reference/trim_.html
It work ... But I found another code !
An example using float() to convert String[]. It's the same idea as int(): *-:)
https://forum.Processing.org/two/discussion/20185/how-to-read-from-a-text-file-to-arraylist-of-pvectors#Item_4
Thanks you !!
size(200,200); int stars=152; String Star = str(stars); String star[] = {Star}; saveStrings("testsaveloadstring.txt",star); String Stars[] = loadStrings("testsaveloadstring.txt"); int test=int(Stars[0]); text(test,25,50);
lol
https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
I assume that you are going to be using small amounts of data (no more than a hundred or so variables). Otherwise, you'd be better off saving them in a direct manner. Also remember that floats saved as Strings can take up a lot more space than they need to, so you convert a float into a byte array before saving, then load the byte array and convert back to float.
This page details how to do that both manually, and also while saving.