Need help with save"txt
Root / Programming Questions / [.]
Put this code near the beginning:
VAR SAVEIt will make an array (essentially a bunch of variables put into one) that will store your save data. When you want to save, use this:
SAVE=ATK SAVE=DEF SAVE=GOLD SAVE=HP SAVE=SP SAVE "DAT:SAVEDATA",SAVEThe first 5 lines put your variables into the array, and the final line saves the array as a DAT file.
When you want to load, use this:
Side NoteArrays start with 0 for some reason... If you have an array with 5 things in it, the array will go from 0-4. Odd.
LOAD "DAT:SAVEDATA",SAVE,0 ATK=SAVE DEF=SAVE GOLD=SAVE HP=SAVE SP=SAVEIf I remember correctly, this will only work with integers. You can't save real numbers as DAT files. (Integers are variables that can't have decimal points and real numbers are the ones that can) If your numbers ARE real numbers, then you can use this method, but it's a bit more complex. It's like your original method, but it puts multiple numbers into one string. To save, use these lines of code:
SAVE$=STR$(ATK)+"*"+STR$(DEF)+"*"+STR$(GOLD)+"*"+STR$(HP)+"*"+STR$(SP) SAVE "TXT:SAVEDATA",SAVE$The first line puts all the variables together, separated by *s using the STR$ function, which converts numbers to strings. Here's where it gets complex. To load, use these lines of code:
LOAD "TXT:SAVEDATA",0 OUT SAVE$ ATK=VAL(MID$(SAVE$,0,INSTR(SAVE$,"*"))) SAVE$=MID$(SAVE$,INSTR(SAVE$,"*")+1,LEN(SAVE$)-INSTR(SAVE$,"*")) DEF=VAL(MID$(SAVE$,0,INSTR(SAVE$,"*"))) SAVE$=MID$(SAVE$,INSTR(SAVE$,"*")+1,LEN(SAVE$)-INSTR(SAVE$,"*")) GOLD=VAL(MID$(SAVE$,0,INSTR(SAVE$,"*"))) SAVE$=MID$(SAVE$,INSTR(SAVE$,"*")+1,LEN(SAVE$)-INSTR(SAVE$,"*")) HP=VAL(MID$(SAVE$,0,INSTR(SAVE$,"*"))) SAVE$=MID$(SAVE$,INSTR(SAVE$,"*")+1,LEN(SAVE$)-INSTR(SAVE$,"*")) SP=VAL(SAVE$)Oh boy... This is a mess. This chunk of code takes each value out of SAVE$, one by one. As you can see, there are two core copy-and-pasted lines in this: the VAL(...) and the MID$(...). The VAL() line pretty much says "find the first value I see out of the SAVE$ variable and put it into ATK, DEF, etc." The MID$() line takes what it just found out of the SAVE$ variable. The last VAL() line is different because there are no *s left in the SAVE$ variable, so it just takes the last value and puts it into SP. Edit: how did i not see the mistake
Syntax error on what line? Also, LEFT$ and RIGHT$ are your friends.
I tried it and it gave me type mismatch. DAT didn't work need to figure out txt I know txt works I just don't how to save multiple variables at once. Have you tested the DAT code because last time I tried it didn't work here's the key for the rpg I'm working on see if you can get save function to work D4X2E4D
VAR Stats Stats = atk Stats = dfn Stats = hpv Stats = hpm Stats = coin Stats = lvl Stats = c Stats = armor Stats = eq SAVE "STATS",Stats
Try putting DAT: at the beginning of the filename (inside "").
Arrow, I would appreciate it if you learned how to use a forum. This isn't like text messaging: in a forum, you usually make a single post as a response and edit it when you need to add stuff. The only time you should add a new post is if you're replying or if what you're posting has absolutely NOTHING to do with your previous post. I'm fixing your posts; please keep this in mind in the future.
It makes it very difficult to help you when you 'forget' things like that. If you want help, I suggest you 'remember' to give accurate information. What line gives the type mismatch?
(count to 3) And what's on line 1350?
The variable STATS: is there one or more DIM or VAR lines declaring it? Where are they (specifically, inside or outside DEF blocks)?
If the variable STATS is not declared, that's a problem. At or near the beginning of your code (but after CLEAR, if you use it), include
DIM STATS(or 5 or whatever the proper number is).