LoginLogin

Save files in SmileBASIC

Root / Submissions / [.]

joelableCreated:
Introduction It's quite simpler that in Petit Computer, instead of using GRP files or whatever, seperate programs can be used as save files, using a seperate SLOT and using the commands PRGEDIT, PRGSET, AND PRGGET$. Commands •PRGEDIT Syntax: PRGEDIT (Program SLOT),(Line number) Program SLOT is which SLOT you want to get the stuff from. Putting in the currently used slot will give an error. Line number is the line you wish to manipulate and get strings from. If omitted, it will be the first line. If -1 then it will be the last line. •PRGSET Syntax: PRGSET "(Character string)" Character string is what you want replace the current line with. •PRGGET$ Syntax: (Variable)=PRGGET$() Gets a string from the line specified from PRGEDIT. Examples of how to use •Basic Use First of all, you should load the save file on a different SLOT than the main program.
LOAD "PRG1:SAVEFILE"
The you can use PRGEDIT to select where your memory is. Then use PRGGET$ to retrieve what's on the line. Like this: SLOT 0
LOAD "PRG1:SAVE"
PRGEDIT 1,2
CASH=VAL(PRGGET$)
?CASH
SLOT 1
CASH FILE
500
That takes the 500 from the second SLOT, converts from a string to a value, and prints it in the main SLOT.

Is the best way to save large amounts of data, or should I take a different route?

Replying to:mystman12
Is the best way to save large amounts of data, or should I take a different route?
oof uhh you could ask others how to use DAT files, they seem to work but i dont like them kinda late whoops

I don't know how to save,, pls help ;=;

okay I stumbled across this today and um no. SAVE can write a string directly to a file (example from builtin manual):
SAVE "TXT:MEMOFILE",TX$
as well as load a text-type file directly into a string.
TX$=LOAD("TXT:MEMOFILE")
Loading to a program slot does have the nice advantage of being able to read line-by-line but this can be accomplished with a SPLIT$() function anyway.
12Me21 FastSplit implementation
'12me21 new (fast) SPLIT
'http://scratch.smilebasicsource.com/chatlogs/17-01-04.txt@[17:56]
'claims at least 435ms per 10000
DEF SPLIT$(S$,D$)
 VAR LD%=LEN(D$)
 DIM R$[1]
 VAR N%=INSTR(S$,N%)
 IF N%==-1 THEN
  R$[0]=S$
  RETURN R$
 ENDIF
 R$[0]=LEFT$(S$,N%)
 @L
 VAR L%=N%+LD%
 N%=INSTR(L%,S$,D$)
 IF N%==-1 THEN
  PUSH R$,MID$(S$,L%,&H7FFFFFFF)
  RETURN R$
 ENDIF
 PUSH R$,MID$(S$,L%,N%-L%)
 GOTO @L
END
I'm not sure what the approach here does besides waste a program slot.