Author Topic: A truly Mind Boggling issue,  (Read 3212 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
A truly Mind Boggling issue,
« on: May 14, 2021, 11:15:38 pm »
Mysterious value changing, WHY?
the values in Location_Checker are being changed with in the SUB but I can't find where I am changing them!?
Just walk straight left when you run the program, it will try to enter the town, that when the numbers get changed

Code: QB64: [Select]
  1. 'World of Palma; Exploration demo
  2. '5/12/2021
  3. 'Collision checking OFF version
  4. 'Cobalt
  5. TYPE WorldTiles
  6.  Is_Walkable AS _BYTE
  7.  Is_Animated AS _BYTE
  8.  Encounter_Group AS _BYTE 'what types of creature encounters possible
  9.  Is_Village AS _BYTE
  10.  Is_Cave AS _BYTE 'Covers all Cave-like locations
  11.  Display_Layer AS _BYTE 'for tiles that the player can walk under
  12. TYPE TownTiles
  13.  Is_Walkable AS _BYTE
  14.  Is_Animated AS _BYTE
  15.  Is_NPC_Location AS _BYTE 'where the NPCs stand
  16.  Is_Building AS _BYTE 'covers shops and houses
  17.  Is_Exit AS _BYTE
  18. TYPE PlayerTemp
  19.  Wx AS INTEGER
  20.  Wy AS INTEGER
  21.  Tx AS _BYTE
  22.  Ty AS _BYTE
  23.  Fr AS _BYTE
  24.  Is_Intown AS _BYTE
  25. TYPE TownData
  26.  Start_X AS INTEGER 'When entering a town player start here
  27.  Start_Y AS INTEGER
  28.  Exit_X AS INTEGER 'When leaving a town player starts in world here
  29.  Exit_Y AS INTEGER
  30. TYPE StartData
  31.  Map AS _BYTE
  32. TYPE ExitData
  33.  Map AS _BYTE
  34.  
  35. SCREEN _NEWIMAGE(700, 480, 32)
  36. DIM SHARED Map(128, 96) AS WorldTiles, TownMap(9, 50, 39) AS TownTiles, P AS PlayerTemp
  37. DIM SHARED char&, MapAni&, TileX2&, frame%, FPSC%, g.facing AS _BYTE, g.moving AS _BYTE
  38. DIM SHARED Conv&, AlisAnim(4) AS _BYTE
  39. DIM SHARED AnimationOrder(3, 8) '8 frames for sync between Waves\marsh and Shore animations
  40. DIM SHARED Enter(10) AS StartData
  41. DIM SHARED Exits(10) AS ExitData
  42. 'time for the layer system
  43. DIM SHARED Layer(26) AS LONG
  44. Layer(0) = _DISPLAY
  45. Layer(1) = _NEWIMAGE(640, 480, 32)
  46. Layer(2) = _NEWIMAGE(640, 480, 32)
  47.  
  48. MFI_Loader "PS_Overworld_Test.MFI"
  49.  
  50. _CLEARCOLOR _RGB32(62), char&
  51. 'place the conveyor system in corect world location
  52. CONST Conveyor_1_Pos_X = 32 * 82
  53. CONST Conveyor_1_Pos_Y = 32 * 53 + 8
  54. CONST Conveyor_2_Pos_X = 32 * 79 + 8
  55. CONST Conveyor_2_Pos_Y = 32 * 56
  56. CONST Conveyor_Frame_Speed = 2
  57. '--------------------------------------------------
  58. DATA 0,1,2,3,4,4,1,0: 'shore animation order
  59. FOR i%% = 0 TO 7
  60.  READ AnimationOrder(1, i%%)
  61. NEXT i%%
  62. DATA 0,1,2,1: 'animation frame order
  63. FOR i%% = 0 TO 3
  64.  READ AlisAnim(i%%)
  65. NEXT i%%
  66. DATA 36,18,0
  67. DATA 85,47,-1
  68. READ Enter(1).X, Enter(1).Y, Enter(1).Map
  69. READ Exits(1).X, Exits(1).Y, Exits(1).Map
  70. 'Enter Camineet from over world
  71. Map(82, 46).Is_Village = 1
  72. Map(83, 46).Is_Village = 1
  73. Map(82, 47).Is_Village = 1
  74. Map(83, 47).Is_Village = 1
  75. '------------------------------
  76. 'Exit Camineet to over world
  77. TownMap(0, 39, 18).Is_Exit = 1
  78. TownMap(0, 38, 18).Is_Exit = 1
  79. TownMap(0, 21, 27).Is_Exit = 1
  80. TownMap(0, 20, 27).Is_Exit = 1
  81. 'Exit Camineet to Space port(if player has roadpass
  82. TownMap(0, 11, 19).Is_Exit = 2
  83. TownMap(0, 11, 20).Is_Exit = 2
  84. '------------------------------
  85. CONST TRUE = -1, FALSE = NOT TRUE
  86. CONST Default_Key_Right = 19712, Default_Key_Left = 19200, Default_Key_Up = 18432, Default_Key_Down = 20480
  87. CONST Default_A_Button = 32, Default_B_Button = 13, Default_Start_Button = 65, Default_Select_Button = 66
  88. CONST down = 0, up = 1, right = 2, left = 3
  89.  
  90. ON TIMER(T2!, 1) FPS
  91.  
  92. 'TIMER(T2!) ON
  93. P.Wx = Exits(1).X
  94. P.Wy = Exits(1).Y
  95. P.Is_Intown = -1
  96. _DEST Layer(2)
  97.  
  98.  IF CheckFlag%% THEN Location_Checker P.Is_Intown, P.Wx, P.Wy: CheckFlag%% = FALSE
  99.  IF P.Is_Intown > -1 THEN
  100.   TownMap_Tile_loader P.Wx, P.Wy, P.Tx, P.Ty 'Mapx%, Mapy%, Playrx%, Playry%
  101.   _PRINTSTRING (640, 45), "ID-" + STR$(TownMap(P.Is_Intown, P.Wx, P.Wy).Id), Layer(0)
  102.   _PRINTSTRING (640, 60), "UP-" + STR$(TownMap(P.Is_Intown, P.Wx, P.Wy - 1).Id) + " ", Layer(0)
  103.   _PRINTSTRING (640, 75), "DN-" + STR$(TownMap(P.Is_Intown, P.Wx, P.Wy + 1).Id) + " ", Layer(0)
  104.   _PRINTSTRING (640, 90), "LT-" + STR$(TownMap(P.Is_Intown, P.Wx - 1, P.Wy).Id) + " ", Layer(0)
  105.   _PRINTSTRING (640, 105), "RT-" + STR$(TownMap(P.Is_Intown, P.Wx + 1, P.Wy).Id) + " ", Layer(0)
  106.   _PRINTSTRING (640, 120), "XT-" + STR$(TownMap(P.Is_Intown, P.Wx + 1, P.Wy).Is_Exit) + " ", Layer(0)
  107.   _PRINTSTRING (640, 135), "TwN-" + STR$(P.Is_Intown) + " ", Layer(0)
  108.   Map_Loader_tiled_Base P.Wx, P.Wy, P.Tx, P.Ty 'Mapx%, Mapy%, Playrx%, Playry%
  109.   _PRINTSTRING (640, 45), "ID-" + STR$(Map(P.Wx, P.Wy).Id), Layer(0)
  110.   _PRINTSTRING (640, 60), "UP-" + STR$(Map(P.Wx, P.Wy - 1).Id) + " ", Layer(0)
  111.   _PRINTSTRING (640, 75), "DN-" + STR$(Map(P.Wx, P.Wy + 1).Id) + " ", Layer(0)
  112.   _PRINTSTRING (640, 90), "LT-" + STR$(Map(P.Wx - 1, P.Wy).Id) + " ", Layer(0)
  113.   _PRINTSTRING (640, 105), "RT-" + STR$(Map(P.Wx + 1, P.Wy).Id) + " ", Layer(0)
  114.  _PRINTSTRING (640, 0), "FPS-" + STR$(FPSC%), Layer(0)
  115.  _PRINTSTRING (640, 15), "X-" + STR$(P.Wx), Layer(0)
  116.  _PRINTSTRING (640, 30), "Y-" + STR$(P.Wy), Layer(0)
  117.  Place_Alis
  118.  _PUTIMAGE , Layer(2), Layer(1)
  119.  CLS , 0
  120.  _PUTIMAGE (0, 0), Layer(1), _DISPLAY
  121.  frame% = frame% + 1
  122.  '-----------------Controls------------------
  123.  IF _KEYDOWN(Default_Key_Up) AND (NOT g.moving) THEN g.facing = up: g.moving = TRUE
  124.  IF _KEYDOWN(Default_Key_Left) AND (NOT g.moving) THEN g.facing = left: g.moving = TRUE
  125.  IF _KEYDOWN(Default_Key_Right) AND (NOT g.moving) THEN g.facing = right: g.moving = TRUE
  126.  IF _KEYDOWN(Default_Key_Down) AND (NOT g.moving) THEN g.facing = down: g.moving = TRUE
  127.  IF _KEYDOWN(27) THEN exitflag%% = -1
  128.  SELECT CASE g.facing
  129.   CASE up
  130.    IF Collision(P.Wx, P.Wy - 1) THEN g.moving = FALSE
  131.   CASE down
  132.    IF Collision(P.Wx, P.Wy + 1) THEN g.moving = FALSE
  133.   CASE left
  134.    IF Collision(P.Wx - 1, P.Wy) THEN g.moving = FALSE
  135.   CASE right
  136.    IF Collision(P.Wx + 1, P.Wy) THEN g.moving = FALSE
  137.  
  138.  '--------------------------------------------
  139.  '----------------Movement--------------------
  140.  IF g.moving THEN
  141.   SELECT CASE g.facing
  142.    CASE up
  143.     P.Ty = P.Ty + 2
  144.     IF (ABS(P.Ty) MOD 32) = 0 THEN g.moving = FALSE: P.Wy = P.Wy - 1: P.Ty = 0: CheckFlag%% = TRUE
  145.     IF NOT _KEYDOWN(Default_Key_Up) THEN Ft%% = 0: P.Fr = 0 ELSE g.moving = TRUE
  146.    CASE down
  147.     P.Ty = P.Ty - 2
  148.     IF (P.Ty MOD 32) = 0 THEN g.moving = FALSE: P.Wy = P.Wy + 1: P.Ty = 0: CheckFlag%% = TRUE
  149.     IF NOT _KEYDOWN(Default_Key_Down) THEN Ft%% = 0: P.Fr = 0 ELSE g.moving = TRUE
  150.    CASE left
  151.     P.Tx = P.Tx + 2
  152.     IF (ABS(P.Tx) MOD 32) = 0 THEN g.moving = FALSE: P.Wx = P.Wx - 1: P.Tx = 0: CheckFlag%% = TRUE
  153.     IF NOT _KEYDOWN(Default_Key_Left) THEN Ft%% = 0: P.Fr = 0 ELSE g.moving = TRUE
  154.    CASE right
  155.     P.Tx = P.Tx - 2
  156.     IF (P.Tx MOD 32) = 0 THEN g.moving = FALSE: P.Wx = P.Wx + 1: P.Tx = 0: CheckFlag%% = TRUE
  157.     IF NOT _KEYDOWN(Default_Key_Right) THEN Ft%% = 0: P.Fr = 0 ELSE g.moving = TRUE
  158.  IF g.moving THEN Ft%% = Ft%% + 1
  159.  IF Ft%% = 8 THEN P.Fr = P.Fr + 1: Ft%% = 0
  160.  IF P.Fr = 4 THEN P.Fr = 0
  161.  'Correct for map wrap
  162.  IF P.Wx = 128 THEN P.Wx = 0
  163.  IF P.Wx = -1 THEN P.Wx = 127
  164.  IF P.Wy = 96 THEN P.Wy = 0
  165.  IF P.Wy = -1 THEN P.Wy = 95
  166.  '--------------------
  167.  IF Enter(1).Y = 0 THEN END
  168.  
  169.  _LIMIT 60
  170. LOOP UNTIL exitflag%%
  171. TIMER(T2!) OFF
  172. _DEST Layer(0)
  173.  
  174. FUNCTION Collision (X1%, Y1%)
  175.  Result%% = TRUE 'always assume collision
  176.  IF P.Is_Intown > -1 THEN
  177.   IF TownMap(P.Is_Intown, X1%, Y1%).Is_Walkable THEN Result%% = FALSE
  178.   IF Map(X1%, Y1%).Is_Walkable THEN Result%% = FALSE
  179.  Collision = Result%%
  180.  
  181. SUB Map_Loader_tiled_Base (X1%, Y1%, Sx%, Sy%)
  182.  STATIC SubFrame(3) AS _BYTE, MainFrame(3) AS _BYTE, Triggered%%
  183.  FOR x% = -1 TO 20
  184.   FOR y% = -1 TO 15
  185.    mx% = X1% + x% - 9 '-9 to center on player character
  186.    my% = Y1% + y% - 7 '-7 to center(ish) on player character
  187.    '------Adjust for map wrap around------
  188.    IF mx% < 0 THEN mx% = 128 + mx% 'use addition cause mx% is a negative
  189.    IF mx% > 127 THEN mx% = mx% - 128
  190.    IF my% < 0 THEN my% = 96 + my% 'use addition cause my% is a negative
  191.    IF my% > 95 THEN my% = my% - 96
  192.    '--------------------------------------
  193.    'main map tiles
  194.    _PUTIMAGE (Sx% + x% * 32, Sy% + y% * 32)-STEP(31, 31), TileX2&, Layer(Map(mx%, my%).Display_Layer), (0 + Map(mx%, my%).Id * 34, 0)-STEP(31, 31)
  195.    'animated map tiles
  196.    IF Map(mx%, my%).Is_Animated THEN
  197.     SELECT CASE Map(mx%, my%).Id
  198.      CASE 1 TO 4 'waves
  199.       _PUTIMAGE (Sx% + x% * 32, Sy% + y% * 32)-STEP(31, 31), MapAni&, Layer(1), (544 + MainFrame(1) * 34, 0)-STEP(31, 31)
  200.      CASE 21 TO 25 'marsh
  201.       _PUTIMAGE (Sx% + x% * 32, Sy% + y% * 32)-STEP(31, 31), MapAni&, Layer(1), (544 + (Map(mx%, my%).Id - 21) * 34, 34 + MainFrame(1) * 34)-STEP(31, 31)
  202.      CASE 5 TO 20 'shore
  203.       _PUTIMAGE (Sx% + x% * 32, Sy% + y% * 32)-STEP(31, 31), MapAni&, Layer(1), ((Map(mx%, my%).Id - 5) * 34, AnimationOrder(1, MainFrame(2)) * 34)-STEP(31, 31)
  204.     END SELECT
  205.    END IF
  206.   NEXT y%
  207.  NEXT x%
  208.  'Horizontal conveyor
  209.  _PUTIMAGE (Sx% + Conveyor_1_Pos_X - (X1% * 32), Sy% + Conveyor_1_Pos_Y - (Y1% * 32)), Conv&, Layer(2), (0, 0 + (MainFrame(0) * 34))-STEP(255, 31)
  210.  'vertical conveyor
  211.  _PUTIMAGE (Sx% + Conveyor_2_Pos_X - (X1% * 32), Sy% + Conveyor_2_Pos_Y - (Y1% * 32)), Conv&, Layer(2), (257 + (MainFrame(0) * 34), 0)-STEP(31, 223)
  212.  FOR i%% = 0 TO 2
  213.   SubFrame(i%%) = SubFrame(i%%) + 1
  214.   IF SubFrame(0) = 5 + Conveyor_Frame_Speed THEN MainFrame(0) = MainFrame(0) + Conveyor_Frame_Speed: SubFrame(0) = 0
  215.   IF SubFrame(1) = 16 THEN MainFrame(1) = MainFrame(1) + 1: SubFrame(1) = 0
  216.   IF SubFrame(2) = 24 THEN MainFrame(2) = MainFrame(2) + 1: SubFrame(2) = 0
  217.  NEXT i%%
  218.  IF MainFrame(0) = 8 THEN MainFrame(0) = 0
  219.  IF MainFrame(1) = 4 THEN MainFrame(1) = 0
  220.  IF MainFrame(2) = 8 THEN MainFrame(2) = 0
  221.  
  222. SUB TownMap_Tile_loader (X1%, Y1%, Sx%, Sy%)
  223.  FOR x% = -1 TO 20
  224.   FOR y% = -1 TO 15
  225.    mx% = X1% + x% - 9 '-9 to center on player character
  226.    my% = Y1% + y% - 7 '-7 to center(ish) on player character
  227.    'town map tiles
  228.    _PRINTSTRING (0, 0), STR$(P.Is_Intown) + STR$(mx%) + STR$(my%), Layer(0)
  229.    _PUTIMAGE (Sx% + x% * 32, Sy% + y% * 32)-STEP(31, 31), Layer(3), Layer(1), (0 + TownMap(P.Is_Intown, mx%, my%).Id * 34, 0)-STEP(31, 31)
  230.   NEXT
  231.  
  232. SUB FPS
  233.  ' STATIC LastCount%
  234.  FPSC% = frame%
  235.  frame% = 0
  236.  
  237. SUB Place_Alis
  238.  IF NOT g.moving THEN
  239.   _PUTIMAGE (290, 210)-STEP(31, 45), char&, Layer(1), (0 + 17 * g.facing, 120)-STEP(15, 22)
  240.   _PUTIMAGE (290, 210)-STEP(31, 45), char&, Layer(1), (68 + 51 * g.facing + AlisAnim(P.Fr) * 17, 120)-STEP(15, 22)
  241.  
  242. SUB Location_Checker (Map%%, X%, Y%)
  243.  _PRINTSTRING (0, 0), STR$(Map%%) + STR$(X%) + STR$(Y%), Layer(0)
  244.  IF P.Is_Intown > -1 THEN
  245.  
  246.   IF TownMap(Map%%, X%, Y%).Is_Exit THEN
  247.    P.Is_Intown = Exits(TownMap(Map%%, X%, Y%).Is_Exit).Map
  248.    P.Wx = Exits(TownMap(Map%%, X%, Y%).Is_Exit).X
  249.    P.Wy = Exits(TownMap(Map%%, X%, Y%).Is_Exit).Y
  250.   END IF
  251.   IF Map(X%, Y%).Is_Village THEN
  252.    P.Is_Intown = Enter(Map(X%, Y%).Is_Village).Map
  253.    P.Wx = Enter(Map(X%, Y%).Is_Village).X
  254.    P.Wy = Enter(Map(X%, Y%).Is_Village).Y
  255.    _PRINTSTRING (0, 16), STR$(P.Is_Intown) + STR$(P.Wx) + STR$(P.Wy), Layer(0)
  256.    _PRINTSTRING (0, 32), STR$(Enter(1).Map) + STR$(Enter(1).X) + STR$(Enter(1).Y), Layer(0)
  257.    _PRINTSTRING (0, 48), STR$(Map%%) + STR$(X%) + STR$(Y%), Layer(0)
  258.    _PRINTSTRING (0, 64), STR$(Map(X%, Y%).Is_Village), Layer(0)
  259.  
  260.    END
  261.   END IF
  262.  
  263.  
  264. SUB MFI_Loader (FN$)
  265.  DIM Size(128) AS LONG, FOffset(128) AS LONG
  266.  GET #1, , c~%% 'retrieve number of files
  267.  FOR I~%% = 1 TO c~%%
  268.   GET #1, , FOffset(I~%%)
  269.   GET #1, , Size(I~%%)
  270.   FOffset&(I~%%) = FOffset&(I~%%) + 1
  271.  NEXT I~%%
  272.  
  273.  TileX2& = LoadGFX(FOffset(1), Size(1)) ' _LOADIMAGE("gfx\maps\PalmaTiles2x2.bmp", 32) '_NEWIMAGE(640, 480, 32)
  274.  Conv& = LoadGFX(FOffset(2), Size(2)) '_LOADIMAGE("gfx\maps\conveyoranim.bmp", 32) 'Conveyor
  275.  MapAni& = LoadGFX(FOffset(3), Size(3)) '_LOADIMAGE("gfx\maps\mapanimation.bmp", 32) 'Water, shore, and marsh frames
  276.  char& = LoadGFX(FOffset(4), Size(4)) '_LOADIMAGE("gfx\CharacterSheetC.png", 32) '
  277.  Layer(3) = LoadGFX(FOffset(6), Size(6))
  278.  LoadData FOffset(5), Size(5)
  279.  F1 = FREEFILE
  280.  OPEN "temp.dat" FOR BINARY AS #F1
  281.  GET #F1, , Map()
  282.  CLOSE #F1
  283.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  284.  LoadData FOffset(7), Size(7)
  285.  F1 = FREEFILE
  286.  OPEN "temp.dat" FOR BINARY AS #F1
  287.  GET #F1, , TownMap()
  288.  CLOSE #F1
  289.  
  290.  CLOSE #1
  291.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  292.  
  293. SUB LoadData (Foff&, Size&)
  294.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  295.  OPEN "temp.dat" FOR BINARY AS #3
  296.  dat$ = SPACE$(Size&)
  297.  GET #1, Foff&, dat$
  298.  PUT #3, , dat$
  299.  CLOSE #3
  300.  
  301. REM '$include:'MFI_Loader2.bi'
  302.  
  303. FUNCTION LoadGFX& (Foff&, Size&)
  304.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  305.  OPEN "temp.dat" FOR BINARY AS #3
  306.  dat$ = SPACE$(Size&)
  307.  GET #1, Foff&, dat$
  308.  PUT #3, , dat$
  309.  CLOSE #3
  310.  LoadGFX& = _LOADIMAGE("temp.dat", 32)
  311.  
  312. FUNCTION LoadFFX& (Foff&, Size&, Fize%%)
  313.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  314.  OPEN "temp.dat" FOR BINARY AS #3
  315.  dat$ = SPACE$(Size&)
  316.  GET #1, Foff&, dat$
  317.  PUT #3, , dat$
  318.  CLOSE #3
  319.  LoadFFX& = _LOADFONT("temp.dat", Fize%%, "monospace")
  320.  
  321. FUNCTION LoadSFX& (Foff&, Size&)
  322.  IF _FILEEXISTS("temp.dat") THEN KILL "temp.dat"
  323.  OPEN "temp.dat" FOR BINARY AS #3
  324.  dat$ = SPACE$(Size&)
  325.  GET #1, Foff&, dat$
  326.  PUT #3, , dat$
  327.  CLOSE #3
  328.  LoadSFX& = _SNDOPEN("temp.dat")
  329.  
« Last Edit: May 14, 2021, 11:18:23 pm by Cobalt »
Granted after becoming radioactive I only have a half-life!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: A truly Mind Boggling issue,
« Reply #1 on: May 15, 2021, 03:08:46 am »
Hi Cobalt
I have given a look at code and it seems too linear the code into SUB checker...

If your goal is to PRESERVE the values of parameters passed to the SUB the solution is easy
put each of parameters into brackets passing them for value and not for reference.
Code: QB64: [Select]
  1.     If CheckFlag%% Then Location_Checker (P.Is_Intown), (P.Wx), (P.Wy)

and this is the result
  [ You are not allowed to view this attachment ]  

it needs a closer reasearch to find where the global variable are changed.

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

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A truly Mind Boggling issue,
« Reply #2 on: May 15, 2021, 06:46:34 am »
Change:

SUB Location_Checker (Map%%, X%, Y%)


To:

SUB Location_Checker (tempMap%%, tempX%, tempY%)
Map%% = tempMap%%: X% = tempX%: Y% = tempY%
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: A truly Mind Boggling issue,
« Reply #3 on: May 15, 2021, 06:53:42 am »
Hi Cobalt
I have given a look at code and it seems too linear the code into SUB checker...

If your goal is to PRESERVE the values of parameters passed to the SUB the solution is easy
put each of parameters into brackets passing them for value and not for reference.
Code: QB64: [Select]
  1.     If CheckFlag%% Then Location_Checker (P.Is_Intown), (P.Wx), (P.Wy)

This is a bad habit to fall into, as QB64 doesn’t always allow passing via reference like this.  There’s a few cases where this habit will kill your program completely, with no warning and no message.  (I think it’s from a Windows unregistered seg fault.)  I don’t remember the quirk off the top of my head to cause the issue now —  passing strings via parentheses?  Passing arrays? — but it’s happened to me enough, and it’s such a PITA to sort out and debug, that this method goes high into my list of Things Steve Says Not To Do(tm).
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: A truly Mind Boggling issue,
« Reply #4 on: May 15, 2021, 10:37:24 am »
@SMcNeill
Hi Steve
Yes I Agree that passing by value is not well checked and it can bring you to a mess. But IF you project a SUB to not give back parameters changed the mess disappears.

Moreover yes String and Arrays cannot be passed by value but only by reference.

this your solution is a good universal solution
Quote
SUB Location_Checker (tempMap%%, tempX%, tempY%)
Map%% = tempMap%%: X% = tempX%: Y% = tempY%

but in the specific code Map% X% Y% are parameters that bring lobal shared variables so the code will become

Code: QB64: [Select]
  1. Sub Location_Checker ' (Map%%, X%, Y%)
  2. ' this stores values of global shared variables while the SUB does its work  
  3.   PI = P.Is_Intown
  4.     PX = P.Wx
  5.     PY = P.Wy
  6.     _PrintString (0, 0), Str$(PI) + Str$(PX) + Str$(PY), Layer(0)
  7.     If P.Is_Intown > -1 Then
  8.         ' e' in citta'
  9.         If TownMap(PI, PX, PY).Is_Exit Then ' se esce segna l'uscita
  10.         ' here global shared variables are changed at this istant  so...
  11.     P.Is_Intown = Exits(TownMap(PI, PX, PY).Is_Exit).Map  ' here variables are the same of at entry sub time
  12.             P.Wx = Exits(TownMap(PI, PX, PY).Is_Exit).X   ' here P.Is_InTown is already changed
  13.             P.Wy = Exits(TownMap(PI, PX, PY).Is_Exit).Y   ' here both P.Is_Intown both P.Wx are already changed
  14.         End If
  15.         _PrintString (10, 100), Str$(PI) + Str$(PX) + Str$(PY) + Str$(PI), Layer(0)
  16.         '      _Delay .5
  17.     Else
  18.         _PrintString (10, 120), Str$(PI) + Str$(PX) + Str$(PY) + Str$(PI), Layer(0)
  19.         '       _Delay 0.5
  20.         If Map(PX, PY).Is_Village Then ' se e' villaggio   ' segna l'ingresso in villaggio
  21.         ' here global shared variables are changed at this istant  so...
  22.             P.Is_Intown = Enter(Map(PX, PY).Is_Village).Map   ' here variables are the same of at entry sub time
  23.             P.Wx = Enter(Map(PX, PY).Is_Village).X  ' here P.Is_InTown is already changed but it doesn't matter
  24.             P.Wy = Enter(Map(PX, PY).Is_Village).Y  ' here both P.Is_Intown both P.Wx are already changed and the second variable changes the results
  25.             _PrintString (0, 16), Str$(P.Is_Intown) + Str$(P.Wx) + Str$(P.Wy), Layer(0)
  26.             _PrintString (0, 32), Str$(Enter(1).Map) + Str$(Enter(1).X) + Str$(Enter(1).Y), Layer(0)
  27.             _PrintString (0, 48), Str$(PI) + Str$(PX) + Str$(PY), Layer(0)
  28.             _PrintString (0, 64), Str$(Map(PX, PY).Is_Village), Layer(0)
  29.            ' End
  30.         End If
  31.     End If
  32.  
  33.  

@Cobalt
as you see from my comments to your code the issue is that you're changing  global shared variables during a work with them!
the use of the parameters has hidden  this event to your eyes.
Programming isn't difficult, only it's  consuming time and coffee

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: A truly Mind Boggling issue,
« Reply #5 on: May 15, 2021, 10:41:01 am »
see in my primative little monkey brain this seems like :

Code: QB64: [Select]
  1. Var1 = 4
  2. Var2 = 5
  3. Var3 = 6
  4.  
  5. A = Var1
  6. B = Var2
  7. C = Var3
  8.  
  9. Var1 = Var1 + 1
  10. Var2 = Var2 + 1
  11. Var3 = Var3 + 1
  12.  
  13. PRINT A, B, C
  14.  
And getting an output of  5  6  7

I will have to look at the Dragon Warrior code again, cause I used the exact same method to move the player every time they used stairs in a dungeon and it didn't do this there.
Granted after becoming radioactive I only have a half-life!