Author Topic: Blocking stuff D:  (Read 3608 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Blocking stuff D:
« Reply #15 on: April 05, 2020, 01:37:47 pm »
Hi Prithak

you're welcome!
I can see that you go over very well choosing your  solution for the logical issue.
I'll wait news on this you project.

Good Luck
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Blocking stuff D:
« Reply #16 on: April 07, 2020, 05:17:45 am »
Hi Prithak

looking at your new code I have got the error of Read past end of file...
it seems a glicth of EOF in fact if you see the debug output after reading the second line of data correctly EOF gives still 0 as output and not -1! so the loop tries to read another time and Runtime error!

here code with a raw tracing debug session
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2.  
  3. TYPE vec1
  4.     x AS INTEGER
  5.     y AS INTEGER
  6.     speed AS INTEGER
  7.  
  8. TYPE vec2
  9.     x1 AS INTEGER
  10.     y1 AS INTEGER
  11.     x2 AS INTEGER
  12.     y2 AS INTEGER
  13.     r AS INTEGER
  14.     g AS INTEGER
  15.     b AS INTEGER
  16.     btype AS STRING
  17.     oldx AS INTEGER
  18.     oldy AS INTEGER
  19.     wl AS STRING
  20.  
  21.  
  22. DIM SHARED player AS vec1
  23. DIM SHARED obstacle(9) AS vec2
  24. player.speed = 5
  25.  
  26.  
  27. map = "map1.txt"
  28.  
  29. player.x = _WIDTH / 2
  30. player.y = _HEIGHT / 2
  31.  
  32. openMap
  33. j = 1
  34.     CLS
  35.  
  36.     makeplayer
  37.     playerMovement
  38.  
  39.     FOR j = 1 TO i
  40.         IF obstacle(j).btype = "obs" THEN
  41.             LINE (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2), _RGB32(obstacle(j).r, obstacle(j).g, obstacle(j).b), BF
  42.             IF player.x + 10 >= obstacle(j).x1 AND player.x - 10 <= obstacle(j).x2 AND player.y + 10 >= obstacle(j).y1 AND player.y - 10 <= obstacle(j).y2 THEN
  43.                 player.x = obstacle(j).oldx
  44.                 player.y = obstacle(j).oldy
  45.             ELSE
  46.                 obstacle(j).oldx = player.x
  47.                 obstacle(j).oldy = player.y
  48.             END IF
  49.         ELSEIF obstacle(j).btype = "warp" THEN
  50.             LINE (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2), _RGB32(obstacle(j).r, obstacle(j).g, obstacle(j).b), BF
  51.             IF collision%(obstacle(j).x1, obstacle(j).y1, obstacle(j).x2, obstacle(j).y2) THEN
  52.                 map = obstacle(j).wl ' here there was a mystyping i for j
  53.                 openMap
  54.             END IF
  55.         END IF
  56.     NEXT j
  57.  
  58.     _DISPLAY
  59.     _LIMIT 120
  60.  
  61. SUB openMap ' the program gets past end of file but reads obstacle(i).wl warps
  62.     i = 0
  63.     OPEN map FOR INPUT AS #1
  64.     LOCATE 10
  65.     WHILE NOT EOF(1)
  66.         i = i + 1
  67.         INPUT #1, obstacle(i).btype, obstacle(i).x1, obstacle(i).y1, obstacle(i).x2, obstacle(i).y2, obstacle(i).r, obstacle(i).g, obstacle(i).b
  68.         IF obstacle(i).btype = "warp" THEN INPUT #1, obstacle(i).wl
  69.         ' just some debug prints...
  70.         PRINT "i = ", i
  71.         PRINT obstacle(i).btype, obstacle(i).x1, obstacle(i).y1, obstacle(i).x2, obstacle(i).y2, obstacle(i).r, obstacle(i).g, obstacle(i).b, obstacle(i).wl
  72.         PRINT "EOF"; EOF(1); " press a key for the next run of cycle"
  73.         SLEEP ' just to trace into loop
  74.     WEND
  75.     CLOSE #1
  76.  
  77. SUB makeplayer
  78.     CIRCLE (player.x, player.y), 10, _RGB32(100, 200, 255)
  79.     PAINT (player.x, player.y), _RGB32(100, 200, 255), _RGB32(100, 200, 255)
  80.  
  81. SUB playerMovement
  82.     IF _KEYDOWN(18432) THEN player.y = player.y - player.speed
  83.     IF _KEYDOWN(20480) THEN player.y = player.y + player.speed
  84.     IF _KEYDOWN(19200) THEN player.x = player.x - player.speed
  85.     IF _KEYDOWN(19712) THEN player.x = player.x + player.speed
  86.  
  87. FUNCTION collision% (x1, y1, x2, y2)
  88.     IF player.x >= x1 AND player.x <= x2 AND player.y >= y1 AND player.y <= y2 THEN
  89.         collision% = 1
  90.     END IF
  91.  
But in your PC do all run good?
I have saved the map1.txt and map2.txt copying them and pasting into QB64IDE and after saving to the HDD as txt files.
Can this make a difference? (QB64ide adds something at the end of the file?... just a minute to create another 2 files using notepad.exe of windows....
Yes the solution is that QB64 adds something at the end of the file... now your code works very good
Programming isn't difficult, only it's  consuming time and coffee

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Blocking stuff D:
« Reply #17 on: April 07, 2020, 08:45:28 am »
QB64 adds extra one line at the end of the file and this line just contain CRLF. Due to this, EOF(1) still give 0. Now, since EOF(1) is still false or 0,
input #1,.... is again executed but there are no data due to which "input past end of file" occur.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Prithak

  • Newbie
  • Posts: 56
  • Life itself is a Programming Language!
    • View Profile
    • My Programming Language
Re: Blocking stuff D:
« Reply #18 on: April 07, 2020, 11:41:23 am »
Well, that was odd but glad you got that sorted out lol
CLS
IF computer$ = "ON" THEN
me$ = "Happy!"
ELSE
me$ = "Time To Draw!"
END IF
END

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Blocking stuff D:
« Reply #19 on: April 08, 2020, 04:57:32 pm »
Hi Ashish
thanks to confirm my hypothesis...
so it can be useful to have the option in QB64IDE to save simple TXT file without this CFRL at the end... as can do Qbasic and QB45.

Yes we can do this using another editor for creating and modifing  simple text files... but is it the same thing?
Programming isn't difficult, only it's  consuming time and coffee

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Blocking stuff D:
« Reply #20 on: April 09, 2020, 11:59:15 am »
You could use LINE INPUT to read entire line into a string variable.
If the string variable is equal to CRLF, then read another line from the file.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Blocking stuff D:
« Reply #21 on: April 09, 2020, 04:45:48 pm »
@EricE 
thanks for your idea
but I'm focusing on the fact that for now it is better to use a filedata.txt made by notepad.exe  and not with QB64IDE to not get an error read past of end of file .
Then we can argue about if it is the best way to store informations for a program, but that is another issue about talk.
Programming isn't difficult, only it's  consuming time and coffee

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: Blocking stuff D:
« Reply #22 on: April 09, 2020, 07:27:34 pm »
Quote
Then we can argue about if it is the best way to store informations for a program, but that is another issue about talk.

Glad to see this progressing, great work...now as for storing the data, now your using TYPE's to store the information i'd suggest a binary file and just use PUT/GET, it's easier and file reads are much much faster than INPUT/LINE INPUT.

Unseen

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Blocking stuff D:
« Reply #23 on: April 10, 2020, 08:14:33 pm »
@Unseen Machine
yes this argument is interesting
about using GET and PUT and a different access to the file we must be careful to the UDT with string with variable lenght,
it is easy to GET wrong value from file. It is safe to use Fixed string.

  [ You are not allowed to view this attachment ]  
Programming isn't difficult, only it's  consuming time and coffee

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Blocking stuff D:
« Reply #24 on: April 10, 2020, 09:53:42 pm »
Please note that a variable-length UDT (one with a variable-length string in it) cannot be used with GET or PUT.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Blocking stuff D:
« Reply #25 on: April 11, 2020, 08:57:32 am »
Hi Luke
Thanks to reply
I agree with you at 90%  for these two experiences .


this is about OPEN RANDOM and GET

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2.  
  3. TYPE vec1
  4.     x AS INTEGER
  5.     y AS INTEGER
  6.     speed AS INTEGER
  7.  
  8. TYPE vec2
  9.     x1 AS INTEGER
  10.     y1 AS INTEGER
  11.     x2 AS INTEGER
  12.     y2 AS INTEGER
  13.     r AS INTEGER
  14.     g AS INTEGER
  15.     b AS INTEGER
  16.     btype AS STRING
  17.     oldx AS INTEGER
  18.     oldy AS INTEGER
  19.     wl AS STRING
  20.  
  21.  
  22. DIM SHARED player AS vec1
  23. DIM SHARED obstacle(9) AS vec2
  24. player.speed = 5
  25.  
  26.  
  27. map = "map1.new"
  28.  
  29. player.x = _WIDTH / 2
  30. player.y = _HEIGHT / 2
  31.  
  32. openMap
  33. j = 1
  34.     CLS
  35.     makeplayer
  36.     playerMovement
  37.  
  38.     FOR j = 1 TO i
  39.         IF obstacle(j).btype = "obs" THEN
  40.             LINE (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2), _RGB32(obstacle(j).r, obstacle(j).g, obstacle(j).b), BF
  41.             IF player.x + 10 >= obstacle(j).x1 AND player.x - 10 <= obstacle(j).x2 AND player.y + 10 >= obstacle(j).y1 AND player.y - 10 <= obstacle(j).y2 THEN
  42.                 player.x = obstacle(j).oldx
  43.                 player.y = obstacle(j).oldy
  44.             ELSE
  45.                 obstacle(j).oldx = player.x
  46.                 obstacle(j).oldy = player.y
  47.             END IF
  48.         ELSEIF obstacle(j).btype = "warp" THEN
  49.             LINE (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2), _RGB32(obstacle(j).r, obstacle(j).g, obstacle(j).b), BF
  50.             IF collision%(obstacle(j).x1, obstacle(j).y1, obstacle(j).x2, obstacle(j).y2) THEN
  51.                 map = obstacle(j).wl ' here there was a mystyping i for j
  52.                 openMap
  53.             END IF
  54.         END IF
  55.     NEXT j
  56.  
  57.     _DISPLAY
  58.     _LIMIT 120
  59.  
  60. SUB openMap ' the program gets past end of file but reads obstacle(i).wl warps
  61.     i = 0
  62.     OPEN map FOR RANDOM AS #1
  63.     'len  = len(obstacle()) len of record is managed at level of parser
  64.     'but you can open a file in RANDOM mode without say  how is the size of UDT
  65.     ' if you use the default size or if you use the single fields
  66.     WHILE NOT EOF(1)
  67.         i = i + 1
  68.         ' get #1, , obstacle()  <--  this is managed at level of parser
  69.         GET #1, , obstacle(i).btype
  70.         GET #1, , obstacle(i).x1
  71.         GET #1, , obstacle(i).y1
  72.         GET #1, , obstacle(i).x2
  73.         GET #1, , obstacle(i).y2
  74.         GET #1, , obstacle(i).r
  75.         GET #1, , obstacle(i).g
  76.         GET #1, , obstacle(i).b
  77.         GET #1, , obstacle(i).wl '  <-- this is not managed at level of parser
  78.         ' so a dummy use of GET (like me in this example),
  79.         'reading each field at a time, reads until out of file
  80.  
  81.         ' just some debug prints...
  82.         _DEST _CONSOLE
  83.         PRINT "i = ", i
  84.         PRINT obstacle(i).btype, obstacle(i).x1, obstacle(i).y1, obstacle(i).x2, obstacle(i).y2, obstacle(i).r, obstacle(i).g, obstacle(i).b, obstacle(i).wl
  85.         PRINT "EOF"; EOF(1); " press a key for the next run of cycle"
  86.         _DEST 0
  87.     WEND
  88.     CLOSE #1
  89.  
  90. SUB makeplayer
  91.     CIRCLE (player.x, player.y), 10, _RGB32(100, 200, 255)
  92.     PAINT (player.x, player.y), _RGB32(100, 200, 255), _RGB32(100, 200, 255)
  93.  
  94. SUB playerMovement
  95.     IF _KEYDOWN(18432) THEN player.y = player.y - player.speed
  96.     IF _KEYDOWN(20480) THEN player.y = player.y + player.speed
  97.     IF _KEYDOWN(19200) THEN player.x = player.x - player.speed
  98.     IF _KEYDOWN(19712) THEN player.x = player.x + player.speed
  99.  
  100. FUNCTION collision% (x1, y1, x2, y2)
  101.     IF player.x >= x1 AND player.x <= x2 AND player.y >= y1 AND player.y <= y2 THEN
  102.         collision% = 1
  103.     END IF
  104.  

and this with OPEN BINARY and GET
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2.  
  3. TYPE vec1
  4.     x AS INTEGER
  5.     y AS INTEGER
  6.     speed AS INTEGER
  7.  
  8. TYPE vec2
  9.     x1 AS INTEGER
  10.     y1 AS INTEGER
  11.     x2 AS INTEGER
  12.     y2 AS INTEGER
  13.     r AS INTEGER
  14.     g AS INTEGER
  15.     b AS INTEGER
  16.     btype AS STRING
  17.     oldx AS INTEGER
  18.     oldy AS INTEGER
  19.     wl AS STRING
  20.  
  21.  
  22. DIM SHARED player AS vec1
  23. DIM SHARED obstacle(9) AS vec2
  24. player.speed = 5
  25.  
  26.  
  27. map = "map1.new"
  28.  
  29. player.x = _WIDTH / 2
  30. player.y = _HEIGHT / 2
  31.  
  32. openMap
  33. j = 1
  34.     CLS
  35.     makeplayer
  36.     playerMovement
  37.  
  38.     FOR j = 1 TO i
  39.         IF obstacle(j).btype = "obs" THEN
  40.             LINE (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2), _RGB32(obstacle(j).r, obstacle(j).g, obstacle(j).b), BF
  41.             IF player.x + 10 >= obstacle(j).x1 AND player.x - 10 <= obstacle(j).x2 AND player.y + 10 >= obstacle(j).y1 AND player.y - 10 <= obstacle(j).y2 THEN
  42.                 player.x = obstacle(j).oldx
  43.                 player.y = obstacle(j).oldy
  44.             ELSE
  45.                 obstacle(j).oldx = player.x
  46.                 obstacle(j).oldy = player.y
  47.             END IF
  48.         ELSEIF obstacle(j).btype = "warp" THEN
  49.             LINE (obstacle(j).x1, obstacle(j).y1)-(obstacle(j).x2, obstacle(j).y2), _RGB32(obstacle(j).r, obstacle(j).g, obstacle(j).b), BF
  50.             IF collision%(obstacle(j).x1, obstacle(j).y1, obstacle(j).x2, obstacle(j).y2) THEN
  51.                 map = obstacle(j).wl ' here there was a mystyping i for j
  52.                 openMap
  53.             END IF
  54.         END IF
  55.     NEXT j
  56.  
  57.     _DISPLAY
  58.     _LIMIT 120
  59.  
  60. SUB openMap ' the program gets past end of file but reads obstacle(i).wl warps
  61.     i = 0
  62.     OPEN map FOR BINARY AS #1
  63.     WHILE NOT EOF(1)
  64.         i = i + 1
  65.         ' get #1, , obstacle()  <--  this is managed at level of parser
  66.         GET #1, , obstacle(i).btype
  67.         GET #1, , obstacle(i).x1
  68.         GET #1, , obstacle(i).y1
  69.         GET #1, , obstacle(i).x2
  70.         GET #1, , obstacle(i).y2
  71.         GET #1, , obstacle(i).r
  72.         GET #1, , obstacle(i).g
  73.         GET #1, , obstacle(i).b
  74.         GET #1, , obstacle(i).wl '  <-- this is not managed at level of parser
  75.         ' so a dummy use of GET (like me in this example),
  76.         'reading each field at a time, reads until out of file
  77.  
  78.         ' just some debug prints...
  79.         _DEST _CONSOLE
  80.         PRINT "i = ", i
  81.         PRINT obstacle(i).btype, obstacle(i).x1, obstacle(i).y1, obstacle(i).x2, obstacle(i).y2, obstacle(i).r, obstacle(i).g, obstacle(i).b, obstacle(i).wl
  82.         PRINT "EOF"; EOF(1); " press a key for the next run of cycle"
  83.         _DEST 0
  84.     WEND
  85.     CLOSE #1
  86.  
  87. SUB makeplayer
  88.     CIRCLE (player.x, player.y), 10, _RGB32(100, 200, 255)
  89.     PAINT (player.x, player.y), _RGB32(100, 200, 255), _RGB32(100, 200, 255)
  90.  
  91. SUB playerMovement
  92.     IF _KEYDOWN(18432) THEN player.y = player.y - player.speed
  93.     IF _KEYDOWN(20480) THEN player.y = player.y + player.speed
  94.     IF _KEYDOWN(19200) THEN player.x = player.x - player.speed
  95.     IF _KEYDOWN(19712) THEN player.x = player.x + player.speed
  96.  
  97. FUNCTION collision% (x1, y1, x2, y2)
  98.     IF player.x >= x1 AND player.x <= x2 AND player.y >= y1 AND player.y <= y2 THEN
  99.         collision% = 1
  100.     END IF
  101.  
to run these two examples you must use these two map files attached (so anybody cannot copy and past them into QB64Ide and live a different nightmare about code not working, think about EOF failure <-- also this is a possible not ordinary use of the QB64IDE).

in the two examples the code works bad, but that is the issue of coder, while the possibility to GET a variable string in RANDOM and BINARY mode is an issue of language.

Thanks to read and to talk

PS
I agree that best practice is to use RANDOM and BINARY mode with arrays loading in one shot the whole array, and with UDT loading in one shot the whole UDT, but the other way (using the single Field of an UDT) is there from so far time and it is possible.
I agree that best practice is to save/load data to/from file RANDOM and BINARY by code and not for working with a txt file created by text editor, but it is possible. So can be put a forbidden limit to the use of variable string in a BINARY/RANDOM mode?
Programming isn't difficult, only it's  consuming time and coffee