G-9 2021-04-07 08:44
Still for my RPG 😂
Actually I was thinking about storing user’s name into persistent memory but it wasn’t working. Now I did a basic 6 char limit, with CHR$() and ASC() converting to store numbers instead of letters, then to convert them into letters, and finally matching them to recover the name. Phew.
Does anyone knows a better and simpler way to do that ?
Timo 2021-04-07 16:38
The idea is correct. You can put the code in nice SUBs, so it's easy to use.
This is from https://lowresnx.inutilis.com/topic.php?id=592, but I cleaned the test:
SUB POKEPS(A,S$) L=MIN(255,LEN(S$)) POKE A,L FOR I=1 TO L POKE A+I,ASC(MID$(S$,I,1)) NEXT I END SUB SUB PEEKPS(A,S$) L=PEEK(A) S$="" FOR I=1 TO L S$=S$+CHR$(PEEK(A+I)) NEXT I END SUB
DIM I$,O$ I$="TEST 123" A=$E000 CALL POKEPS(A,I$) CALL PEEKPS(A,O$) PRINT I$ PRINT O$
Timo 2021-04-07 16:40 (Edited)
If you want to save more than one string, make sure the addresses have enough room between them. In theory these SUBs support strings with up to 256 bytes. So you could use these memory addresses:
was8bit 2021-04-07 20:59 (Edited)
One trick i enjoy trying to use is that PERSIST memory is the exact same size as both BG 1 and BG 0 memory... for example, in my Farm Life game, i use the background as game data (no arrays) so i save the game via saving the background memory to /from persist memory, i also store game data on screen, and manually extract them to reload some key variables (like cash, game level, etc)
But for normal games, Timo's approach is best :)