Author Topic: Why is my program hit & miss on the output?  (Read 2666 times)

0 Members and 1 Guest are viewing this topic.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Why is my program hit & miss on the output?
« on: July 24, 2021, 04:15:57 pm »
So roughly 33% of the time this program fails to display any output. its pretty straight forward so I'm at a loss of whats going on. Could I be encountering some kind of race condition somewhere? Given it doesn't happen every time, it may not be easily diagnose-able.
The CONST WALL will need to be changed back to chr$(178)[from the ascii chart in the IDE] once you copy it in the IDE. Like many other places you can not paste the true ASCII(extended) character here. (well at least it wont let me)

Code: QB64: [Select]
  1. DIM SHARED Layer(10) AS LONG
  2. CONST Wall = "²" 'CHR$(178)
  3.  
  4. SCREEN _NEWIMAGE(100, 40, 0)
  5. Layer(0) = _DISPLAY
  6. Layer(1) = _COPYIMAGE(_DISPLAY)
  7. temp = _MEMIMAGE(Layer(1))
  8. FOR i%% = 0 TO 12
  9.  ClearLayer Layer(1)
  10.  SELECT CASE i%%
  11.   CASE 0
  12.    Room00
  13.   CASE 1
  14.    Room01
  15.   CASE 2
  16.    Room02
  17.   CASE 3
  18.    Room03
  19.   CASE 4
  20.    Room04
  21.   CASE 5
  22.    Room05
  23.   CASE 6
  24.    Room06
  25.   CASE 7
  26.    Room07
  27.   CASE 8
  28.    Room08
  29.   CASE 9
  30.    Room09
  31.   CASE 10
  32.    Room10
  33.   CASE 11
  34.    Room11
  35.   CASE 12
  36.    Room12
  37.   CASE 13
  38.    Room12
  39.   CASE 14
  40.    Room03
  41.   CASE 15
  42.    Room03
  43.  
  44.  PCOPY Layer(1), Layer(0)
  45.  LOCATE 35, 1: PRINT "Room"; i%%
  46.  _DELAY 1.25
  47. NEXT i%%
  48.  
  49. SUB ClearLayer (L&)
  50.  old& = _DEST
  51.  _DEST L&
  52.  CLS ' ,0
  53.  _DEST old&
  54.  
  55. SUB ClearLayerTrans (L&)
  56.  old& = _DEST
  57.  _DEST L&
  58.  CLS , 0
  59.  _DEST old&
  60.  
  61. SUB Room00
  62.  'solid room
  63.  FOR i%% = 0 TO 70
  64.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  65.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  66.  NEXT i%%
  67.  FOR i%% = 1 TO 30
  68.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  69.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  70.  NEXT i%%
  71.  
  72. SUB Room01
  73.  'South Exit room
  74.  FOR i%% = 0 TO 70
  75.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  76.  NEXT i%%
  77.  FOR i%% = 0 TO 30
  78.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  79.   _MEMPUT temp, temp.OFFSET + 200 * 31 + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  80.  NEXT i%%
  81.  FOR i%% = 1 TO 30
  82.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  83.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  84.  NEXT i%%
  85.  
  86. SUB Room02
  87.  'North Exit room
  88.  FOR i%% = 0 TO 70
  89.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  90.  NEXT i%%
  91.  FOR i%% = 0 TO 30
  92.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  93.   _MEMPUT temp, temp.OFFSET + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  94.  NEXT i%%
  95.  FOR i%% = 1 TO 30
  96.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  97.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  98.  NEXT i%%
  99.  
  100. SUB Room03
  101.  'West Exit room
  102.  FOR i%% = 0 TO 70
  103.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  104.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  105.  NEXT i%%
  106.  FOR i%% = 1 TO 12
  107.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  108.   _MEMPUT temp, temp.OFFSET + 31 * 200 - i%% * 200, 178 AS _UNSIGNED _BYTE
  109.  NEXT i%%
  110.  FOR i%% = 1 TO 30
  111.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  112.  NEXT i%%
  113.  
  114. SUB Room04
  115.  'East Exit room
  116.  FOR i%% = 0 TO 70
  117.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  118.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  119.  NEXT i%%
  120.  FOR i%% = 1 TO 30
  121.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  122.  NEXT i%%
  123.  FOR i%% = 1 TO 12
  124.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  125.   _MEMPUT temp, temp.OFFSET + 31 * 200 + 140 - (i%% * 200), 178 AS _UNSIGNED _BYTE
  126.  NEXT i%%
  127.  
  128. SUB Room05
  129.  'North + South Exit room
  130.  FOR i%% = 0 TO 30
  131.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  132.   _MEMPUT temp, temp.OFFSET + 200 * 31 + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  133.  NEXT i%%
  134.  FOR i%% = 1 TO 30
  135.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  136.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  137.  NEXT i%%
  138.  
  139.  FOR i%% = 0 TO 30
  140.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  141.   _MEMPUT temp, temp.OFFSET + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  142.  NEXT i%%
  143.  FOR i%% = 1 TO 30
  144.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  145.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  146.  NEXT i%%
  147.  
  148. SUB Room06
  149.  'Ease + West Exit room
  150.  FOR i%% = 0 TO 70
  151.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  152.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  153.  NEXT i%%
  154.  FOR i%% = 1 TO 12
  155.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  156.   _MEMPUT temp, temp.OFFSET + 31 * 200 - i%% * 200, 178 AS _UNSIGNED _BYTE
  157.  NEXT i%%
  158.  FOR i%% = 1 TO 12
  159.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  160.   _MEMPUT temp, temp.OFFSET + 31 * 200 + 140 - (i%% * 200), 178 AS _UNSIGNED _BYTE
  161.  NEXT i%%
  162.  
  163. SUB Room07
  164.  'North + South + West Exit room
  165.  FOR i%% = 0 TO 30
  166.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  167.   _MEMPUT temp, temp.OFFSET + 200 * 31 + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  168.  NEXT i%%
  169.  FOR i%% = 1 TO 12
  170.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  171.   _MEMPUT temp, temp.OFFSET + 31 * 200 - i%% * 200, 178 AS _UNSIGNED _BYTE
  172.  NEXT i%%
  173.  
  174.  FOR i%% = 0 TO 30
  175.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  176.   _MEMPUT temp, temp.OFFSET + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  177.  NEXT i%%
  178.  FOR i%% = 1 TO 30
  179.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  180.  NEXT i%%
  181.  
  182. SUB Room08
  183.  'North + South + East Exit room
  184.  FOR i%% = 0 TO 30
  185.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  186.   _MEMPUT temp, temp.OFFSET + 200 * 31 + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  187.  NEXT i%%
  188.  FOR i%% = 1 TO 30
  189.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  190.  NEXT i%%
  191.  
  192.  FOR i%% = 0 TO 30
  193.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  194.   _MEMPUT temp, temp.OFFSET + 140 - i%% * 2, 178 AS _UNSIGNED _BYTE
  195.  NEXT i%%
  196.  FOR i%% = 1 TO 12
  197.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  198.   _MEMPUT temp, temp.OFFSET + 31 * 200 + 140 - (i%% * 200), 178 AS _UNSIGNED _BYTE
  199.  NEXT i%%
  200.  
  201. SUB Room09
  202.  'North + West exit room
  203.  FOR i%% = 0 TO 70
  204.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  205.  NEXT i%%
  206.  FOR i%% = 1 TO 30
  207.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  208.  NEXT i%%
  209.  FOR i%% = 1 TO 12
  210.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  211.   _MEMPUT temp, temp.OFFSET + 31 * 200 - i%% * 200, 178 AS _UNSIGNED _BYTE
  212.  NEXT i%%
  213.  
  214. SUB Room10
  215.  'North + East exit room
  216.  FOR i%% = 0 TO 70
  217.   _MEMPUT temp, temp.OFFSET + 200 * 31 + i%% * 2, 178 AS _UNSIGNED _BYTE
  218.  NEXT i%%
  219.  FOR i%% = 1 TO 30
  220.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  221.  NEXT i%%
  222.  FOR i%% = 1 TO 12
  223.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  224.   _MEMPUT temp, temp.OFFSET + 31 * 200 + 140 - (i%% * 200), 178 AS _UNSIGNED _BYTE
  225.  NEXT i%%
  226.  
  227. SUB Room11
  228.  'South + West exit room
  229.  FOR i%% = 0 TO 70
  230.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  231.  NEXT i%%
  232.  FOR i%% = 1 TO 30
  233.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  234.  NEXT i%%
  235.  FOR i%% = 1 TO 12
  236.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  237.   _MEMPUT temp, temp.OFFSET + 31 * 200 - i%% * 200, 178 AS _UNSIGNED _BYTE
  238.  NEXT i%%
  239.  
  240. SUB Room12
  241.  'South + East exit room
  242.  FOR i%% = 0 TO 70
  243.   _MEMPUT temp, temp.OFFSET + i%% * 2, 178 AS _UNSIGNED _BYTE
  244.  NEXT i%%
  245.  FOR i%% = 1 TO 30
  246.   _MEMPUT temp, temp.OFFSET + i%% * 200, 178 AS _UNSIGNED _BYTE
  247.  NEXT i%%
  248.  FOR i%% = 1 TO 12
  249.   _MEMPUT temp, temp.OFFSET + 140 + i%% * 200, 178 AS _UNSIGNED _BYTE
  250.   _MEMPUT temp, temp.OFFSET + 31 * 200 + 140 - (i%% * 200), 178 AS _UNSIGNED _BYTE
  251.  NEXT i%%
  252.  
Granted after becoming radioactive I only have a half-life!

FellippeHeitor

  • Guest
Re: Why is my program hit & miss on the output?
« Reply #1 on: July 24, 2021, 04:46:22 pm »
CONST doesn't handle string functions, but that didn't trigger an error until v1.5 - the IDE will properly warn you about that in the latest dev build.

Make your CONST a SHARED STRING instead and all the rest will remain untouched (and work).

FellippeHeitor

  • Guest
Re: Why is my program hit & miss on the output?
« Reply #2 on: July 24, 2021, 04:55:24 pm »
Notice I'm just pointing out the issue with CONST - I didn't run your code, can't offer advice right now.