Author Topic: Help Saving and Loading Data  (Read 5765 times)

0 Members and 1 Guest are viewing this topic.

Offline Zeppelin

  • Newbie
  • Posts: 43
    • View Profile
    • Zeppelin Games ItchIo
Help Saving and Loading Data
« on: September 05, 2018, 04:40:08 am »
Hey,
I need some help loading data from a text file. For some reason when I call DO UNTIL EOF(1) there seems to be no data in the text file, even though there is.
The loaded data should be saved to an array.
The data is layed out in the format:
Name (str)
Health (int)
Atk (int)
Def (int)
Spd(int)

Any other performance tips or bugs found in the attached program, please let me know.

Thanks
Zeppelin

P.s What happened to the old forum? (I haven't been programming for a while and couldn't find it).
* SLAY V4.bas (Filesize: 10.74 KB, Downloads: 217)
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.

Marked as best answer by Zeppelin on September 05, 2018, 02:05:39 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Help Saving and Loading Data
« Reply #1 on: September 05, 2018, 04:58:17 am »
Change the DO WHILE EOF(1) to DO UNTIL EOF(1) and then try it.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Zeppelin

  • Newbie
  • Posts: 43
    • View Profile
    • Zeppelin Games ItchIo
Re: Help Saving and Loading Data
« Reply #2 on: September 05, 2018, 05:05:26 am »
Thanks SMcNeill,
Can't believe it was something so small and simple I was missing.
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Help Saving and Loading Data
« Reply #3 on: September 05, 2018, 05:19:46 am »
It's a subtle thing, but it completely reverses your loop conditions.  For example, compare the following 2 snippets:

DO WHILE hungry
    EatFood
LOOP


DO UNTIL hungry
     EatFood
LOOP

The first says you eat WHILE hungry; the second says to eat UNTIL you get hungry!  Basically with the second, if you're hungry, you refuse food until you die, or if you're full (not hungry), you just keep eatting until you die....

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: Help Saving and Loading Data
« Reply #4 on: September 05, 2018, 04:10:44 pm »
do
'* some code in here
loop until not hungry

this executes code in the do/until loop at least once

Code: QB64: [Select]
  1. x=1
  2. x=x+1
  3.  
x will equal 2 because code in the do/until loop executes at least once.

Code: QB64: [Select]
  1. x=1
  2. do until x>0 * 'you can substitute while in place of until and the result will be the same for the prior and this example.
  3. x=x+1
  4.  
x will equal 1 because the condition at the beginning of the do/loop has already been met.

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: Help Saving and Loading Data
« Reply #5 on: September 05, 2018, 04:27:56 pm »
For larger programs, using FREEFILE to determine an available input or output channel may help.
Code: QB64: [Select]
  1. 'SLAY V4 REMAKE
  2. _TITLE "SLAY V4" 'SET TITLE
  3. _FULLSCREEN 'SET FULLSCREEN
  4.  
  5. 'DECLARE VARIABLES
  6. DIM saveData$(1000)
  7.  
  8. DIM SHARED player.health AS INTEGER
  9. DIM SHARED player.atk AS INTEGER
  10. DIM SHARED player.spd AS INTEGER
  11.  
  12.  
  13. 'GET THE SCREEN DIMSENSIONS
  14. w = _WIDTH
  15.  
  16. 'SET THE COLOR
  17. col = _RGBA(255, 255, 255, 255)
  18.  
  19. 'LOAD SAVE DATA
  20. SlayV4SaveDataChannel% = FREEFILE
  21. IF SlayV4SaveDataChannel% > 0 THEN
  22.     OPEN "SlayV4SaveData.txt" FOR INPUT AS #SlayV4SaveDataChannel%
  23.     DO UNTIL EOF(SlayV4SaveDataChannel%) 'LOOP UNTIL END OF FILE
  24.         filecount = filecount + 1 'COUNT AMOUNT OF LINES
  25.         LINE INPUT #SlayV4SaveDataChannel%, file$
  26.         saveData$(filecount) = file$
  27.     LOOP
  28.     CLOSE #SlayV4SaveDataChannel%
  29.     PRINT "Too many files open."
  30.     _DELAY 3
  31.     BEEP
  32.     SYSTEM
  33.  

Offline Zeppelin

  • Newbie
  • Posts: 43
    • View Profile
    • Zeppelin Games ItchIo
Re: Help Saving and Loading Data
« Reply #6 on: September 05, 2018, 06:53:34 pm »
Thanks for the explications, quick reply and help, SMcNeill and CodeGuy.
I'll have a look into FREEFILE.

Thanks
Zeppelin
+[--->++<]>+.+++[->++++<]>.[--->+<]>+.-[---->+<]>++.+[->+++<]>+.+++++++++++.----------.[--->+<]>----.+[---->+<]>+++.---[->++++<]>.------------.+.++++++++++.+[---->+<]>+++.+[->+++<]>++.[--->+<]>+.[->+++<]>+.++++++++++.+.>++++++++++.