? Need help with save"txt (Page 1) ● SmileBASIC Source Forums

Sign In

*Usernames are case-sensitive
Forgot my password
What's going on?? See: Site Update March 2022

Need help with save"txt

1 2
  • #1 ✎ 43 Arrow Still trying TO make a save function how to use save"txt with array to create save function so players can save progress Posted
  • #2 ✎ 43 Arrow I got it to save using save"txt for each variable but that would have me saving a bunch of times every time I want to save so I need an array Posted
  • #3 ✎ 272 TheV360 Pokemon Is Awesome! I love Pokemon! Express Yourself First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Are the things you are saving numbers? Posted
  • #4 ✎ 43 Arrow I'm creating a rpg the variables I'm trying to save are for the players stats Atk,Def,gold,hp,sp Posted
  • #5 ✎ 272 TheV360 Pokemon Is Awesome! I love Pokemon! Express Yourself First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Put this code near the beginning: VAR SAVE[5] It 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[0]=ATK SAVE[1]=DEF SAVE[2]=GOLD SAVE[3]=HP SAVE[4]=SP SAVE "DAT:SAVEDATA",SAVE The first 5 lines put your variables into the array, and the final line saves the array as a DAT file. Arrays start with 0 for some reason... If you have an array with 5 things in it, the array will go from 0-4. Odd. When you want to load, use this: LOAD "DAT:SAVEDATA",SAVE,0 ATK=SAVE[0] DEF=SAVE[1] GOLD=SAVE[2] HP=SAVE[3] SP=SAVE[4] If 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 Posted Edited by TheV360
  • #6 ✎ 43 Arrow It gave me syntax error Posted
  • #7 ✎ 477 SquareFingers Syntax error on what line? Also, LEFT$ and RIGHT$ are your friends. Posted
  • #8 ✎ 1884 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself for saving numbers, I strongly reccommend that you use DAT files VAR SAVEARRAY[5] ... SAVEARRAY[0]=ATK SAVEARRAY[1]=DEF SAVEARRAY[2]=GOLD SAVEARRAY[3]=HP SAVEARRAY[4]=SP SAVE "DAT:SAVEFILE",SAVEARRAYand then LOAD "DAT:SAVEFILE",SAVEARRAY ATK=SAVEARRAY[0]etc. to load Posted
  • #9 ✎ 43 Arrow 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[9] Stats[0] = atk Stats[1] = dfn Stats[2] = hpv Stats[3] = hpm Stats[4] = coin Stats[5] = lvl Stats[6] = c Stats[7] = armor Stats[8] = eq SAVE "STATS",Stats Posted Edited by randomous
  • #10 ✎ 477 SquareFingers Try putting DAT: at the beginning of the filename (inside ""). Posted
  • #11 ✎ 1110 randomous Owner Robot Hidden Easter Eggs Second Year My account is over 2 years old Website Drawing I like to draw! Hobbies 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. Posted
  • #12 ✎ 43 Arrow I did in the code I forgot that part when I was making the post Also, here's more code: LOAD "STATS"Stats ATK=Stats[0] DFN=Stats[1] HPV=Stats[2] HPM=Stats[3] COIN=Stats[4] LVL=Stats[5] C=Stats[6] ARMOR=Stats[7] EQ=Stats[8] Posted Edited by randomous
  • #13 ✎ 477 SquareFingers 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? Posted Edited by SquareFingers
  • #14 ✎ 43 Arrow Sorry about that I messed because I'm half asleep my cousin kept me up late last night Type mismatch in 1350 Posted
  • #15 ✎ 477 SquareFingers (count to 3) And what's on line 1350? Posted
  • #16 ✎ 43 Arrow LOAD "DAT:STATS",STATS Posted
  • #17 ✎ 477 SquareFingers The variable STATS: is there one or more DIM or VAR lines declaring it? Where are they (specifically, inside or outside DEF blocks)? Posted
  • #18 ✎ 43 Arrow Not that I can find the key is D4X2E4D can you check it Posted
  • #19 ✎ 43 Arrow I don't think DAT will work I've gotten TXT to work but not the way I need Posted
  • #20 ✎ 477 SquareFingers 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[9] (or 5 or whatever the proper number is). Posted
1 2