Author Topic: Incorrect Array type passed to function error  (Read 2693 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
Incorrect Array type passed to function error
« on: March 06, 2019, 07:46:12 pm »
Ok I've stared at this code for about the last 15 mins and even tried changing the setting up of the arrays but the error persists. Can anyone else figure out why this is saying I'm trying to pass the wrong type of array to my function?

The Error is on line 71(and probably  73,75,77 as they all use the same array elements)
Code: QB64: [Select]
  1. TYPE Game_Data
  2.  Allow_Reverse AS _BYTE
  3.  Level AS _BYTE
  4.  Button AS INTEGER
  5.  MouseX AS INTEGER
  6.  MouseY AS INTEGER
  7.  
  8. CONST TRUE = -1, FALSE = NOT TRUE, DOWN = 1, UP = 2
  9. CONST Total_Words = 30
  10. CONST Words_to_Find = 5
  11.  
  12. DIM G AS Game_Data
  13. DIM Columns(10) AS _BYTE
  14. DIM Grid(80, 60) AS STRING * 1
  15. DIM GridColor(80, 60) AS _UNSIGNED LONG
  16. DIM WordList(Total_Words) AS STRING
  17. DIM Words(Words_to_Find) AS STRING
  18. DIM WordStart(Words_to_Find) AS _BYTE
  19. DIM WordStop(Words_to_Find) AS _BYTE
  20. DIM WordMethod(Words_to_Find) AS _BYTE
  21.  
  22. Columndata:
  23. DATA 16,18,20,24,26
  24.  
  25. WordsList:
  26. DATA BASIC,APPLE,PEACH,COMPUTER,TRICYCLE
  27. DATA TORNADO,GARBAGE,SUNSHINE,PRETTY,MEDIA
  28. DATA EXPERIMENT,TECHNIQUE,CHALLENGE,ACTIVE,SPEECH
  29. DATA TRADITION,COFFEE,MEMORY,STANDING,ORANGE
  30. DATA DRAMA,FOUNDATION,LISTEN,NATURAL,WATER
  31. DATA SUPPORT,TYRANNY,DINOSAUR,COBRA,PUPPY
  32.  
  33. 'Empty the grid field
  34. FOR r%% = 1 TO 60
  35.  FOR c%% = 1 TO 80
  36.   Grid(c%%, r%%) = ""
  37.   GridColor(c%%, r%%) = _RGB32(6, 6, 6)
  38.  NEXT c%%
  39. NEXT r%%
  40.  
  41. 'load the word list
  42. FOR i%% = 1 TO Total_Words
  43.  READ WordList(i%%)
  44. NEXT i%%
  45.  
  46. 'Pick words for current Game
  47. FOR i%% = 1 TO Words_to_Find
  48.  DO
  49.   w%% = INT(RND * Total_Words) + 1
  50.   IF WordList(w%%) <> "" THEN Is_Good = TRUE ELSE Is_Good = FALSE
  51.  LOOP UNTIL Is_Good
  52.  
  53.  'now Place word in current list
  54.  SWAP Words(i%%), WordList(w%%)
  55. NEXT i%%
  56.  
  57. '---------Lets find a place for each word--------
  58. FOR i%% = 1 TO Words_to_Find
  59.  DO
  60.   '----Find a Place to start word----
  61.   DO
  62.    col%% = INT(RND * Columns(G.Level)) + 1
  63.    row%% = INT(RND * (Columns(G.Level) \ 2)) + 1
  64.    IF Grid(col%%, row%%) = "" THEN Is_Good%% = TRUE ELSE Is_Good%% = FALSE
  65.   LOOP UNTIL Is_Good%%
  66.   '----------------------------------
  67.   '---------Try to Place word--------
  68.   SELECT CASE INT(RND * 4) + 1
  69.    CASE 1
  70.    It_Works%%=Horz_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level),G.Allow_Reverse)
  71.   case 2
  72.    It_Works%%=Vert_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level)/2,G.Allow_Reverse)
  73.   case 3
  74.    It_Works%%=Diag_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level),G.Allow_Reverse,DOWN)
  75.   case 4
  76.    It_Works%%=Diag_fit(Grid(),Words(),Col%%,Row%%,I%%,Columns(G.level),G.Allow_Reverse,UP)
  77. '----------------------------------
  78.  Loop until It_Works%%
  79. Next i%%
  80. '------------------------------------------------
  81.  
  82. '-Fill in rest of the space with random letters--
  83. FOR row%% = 1 TO Columns(g.level)/2
  84.  FOR col%% = 1 TO columns(g.level)
  85.   IF Grid(col%%, row%%) = "" THEN
  86.    Grid(col%%, row%%) = CHR$(64 + INT(RND * 26) + 1)
  87.   END IF
  88.  NEXT Col%%
  89. NEXT Row%%
  90. '------------------------------------------------
  91. 'display the grid!
  92. line(0,0)-step(639,479),_RGB32(255,223,79),bf
  93. PrintGrid Columns(G.level)
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. Sub PrintGrid(CC%%)
  104. 'CC%%-- Column count (Passed as Columns(G.Level))
  105.  Locate 1, 1
  106.  FOR Row%% = 1 TO CC%%/2
  107.   FOR Col%% = 1 TO CC%%
  108.    COLOR _RGB32(GridColor(col%%, row%%))
  109.    PRINT Grid(col%%, row%%);
  110.   NEXT Col%%
  111.  NEXT Row%%
  112.  
  113. Function Horz_Fit(WG$(),WA$(),Col%%,Row%%,CW%%,CC%%,AR%%)
  114. 'WG$()- Word Grid array
  115. 'WA$()- Word array
  116. 'Col%%- Column of Word Grid
  117. 'Row%%- Row of Word Grid
  118. 'CW%%-- Current Word array element
  119. 'CC%%-- Column count (Passed as Columns(G.Level))
  120. 'AR%%-- Allow Reversed word flag(passed as G.Allow_Reverse)
  121.  
  122. 'see if the word will even fit here
  123.  WordLength%%=len(WA$(cw%%))
  124.  LeftLength%%=CC%%-col%%
  125.  
  126.  if WordLenght%%<=LeftLength%% then
  127.  'if the word fits
  128.   if AR%% and Int(Rnd*100)>49 then
  129.   'see if the letters work backwards
  130.    for i%%=0 to WordLength%%-1
  131.     if WG$(col%%+i%%,row%%)<>"" and WG$(col%%+i%%,row%%)<>mid$(WA$(cw%%),WordLength%%-i%%,1) then Failed_Reverse%%=True:I%%=WordLength%%+1:Result%%=FALSE else Failed_Reverse%%=false
  132.    next i%%
  133.  
  134.    if NOT failed_reverse%% then
  135.    'the word will work, write it to grid
  136.     Result%%=TRUE 'function will return success
  137.     for i%%=0 to WordLength%%-1
  138.      wg$(col%%+i%%,row%%)=mid$(Wa$(CW),wordlength%%-i%%,1)
  139.     next i%%
  140.    end if
  141.   else
  142.    Failed_reverse%%=true 'set due to not using reverse
  143.   end if
  144.  
  145.   if Failed_Reverse%% then 'try going forward
  146.    for i%%=0 to wordlength%%-1
  147.     if wg$(col%%+i%%,row%%)<>"" and wg$(col%%+i%%,row%%)<>mid$(wa$(cw%%),i%%+1,1) then result%%=FALSE:I%%=Wordlength%%+1 else Result%%=true
  148.    next i%%
  149.  
  150.    if result%%=true then
  151.     FOR i%% = 0 TO wLen - 1
  152.     wG$(col%% + i%%, row%%) = MID$(wa$(cw), i%% + 1, 1)
  153.     next i%%
  154.    end if
  155.  Horz_Fit=result%%
  156.  
  157. Function Vert_Fit(WG$(),WA$(),Col%%,Row%%,CW%%,RC%%,AR%%)
  158. 'WG$()- Word Grid array
  159. 'WA$()- Word array
  160. 'Col%%- Column of Word Grid
  161. 'Row%%- Row of Word Grid
  162. 'CW%%-- Current Word array element
  163. 'RC%%-- Row count (Passed as Columns(G.Level)/2)
  164. 'AR%%-- Allow Reversed word flag(passed as G.Allow_Reverse)
  165.  
  166. 'see if the word will even fit here
  167.  WordLength%%=len(WA$(cw%%))
  168.  LeftLength%%=RC%%-Row%%
  169.  
  170.  if WordLenght%%<=LeftLength%% then
  171.  'if the word fits
  172.   if AR%% and Int(Rnd*100)>49 then
  173.   'see if the letters work backwards
  174.    for i%%=0 to WordLength%%-1
  175.     if WG$(col%%,row%%+i%%)<>"" and WG$(col%%,row%%+i%%)<>mid$(WA$(cw%%),WordLength%%-i%%,1) then Failed_Reverse%%=True:I%%=WordLength%%+1:Result%%=FALSE else Failed_Reverse%%=false
  176.    next i%%
  177.  
  178.    if NOT failed_reverse%% then
  179.    'the word will work, write it to grid
  180.     Result%%=TRUE 'function will return success
  181.     for i%%=0 to WordLength%%-1
  182.      wg$(col%%,row%%+i%%)=mid$(Wa$(CW),wordlength%%-i%%,1)
  183.     next i%%
  184.    end if
  185.   else
  186.    Failed_reverse%%=true 'set due to not using reverse
  187.   end if
  188.  
  189.   if Failed_Reverse%% then 'try going forward
  190.    for i%%=0 to wordlength%%-1
  191.     if wg$(col%%,row%%+i%%)<>"" and wg$(col%%,row%%+i%%)<>mid$(wa$(cw%%),i%%+1,1) then result%%=FALSE:I%%=Wordlength%%+1 else Result%%=true
  192.    next i%%
  193.  
  194.    if result%%=true then
  195.     FOR i%% = 0 TO wLen - 1
  196.     wG$(col%%, row%%+i%%) = MID$(wa$(cw), i%% + 1, 1)
  197.     next i%%
  198.    end if
  199.  Vert_Fit=result%%
  200.  
  201. Function Diag_Fit(WG$(),WA$(),Col%%,Row%%,CW%%,CC%%,AR%%,D%%)
  202. 'WG$()- Word Grid array
  203. 'WA$()- Word array
  204. 'Col%%- Column of Word Grid
  205. 'Row%%- Row of Word Grid
  206. 'CW%%-- Current Word array element
  207. 'CC%%-- Column count (Passed as Columns(G.Level))
  208. 'AR%%-- Allow Reversed word flag(passed as G.Allow_Reverse)
  209. 'D%%--- Direction Flag(1-Down,2-Up)
  210.  
  211.  WordLength%%=len(WA$(cw%%))
  212.  
  213.  case 1'Diagonal Down
  214.  'see if the word will even fit here
  215.   HorzLeftLen%%=CC%%-col%%
  216.   VertLeftLen%%=CC%%/2-row%%
  217.   If VertLeftLen%%>HorzLeftLen%% then LeftLength%%=HorzLeftLen%% else LeftLength%%=VertLeftLen%%
  218.  
  219.   if WordLenght%%<=LeftLength%% then
  220.   'if the word fits
  221.    if AR%% and Int(Rnd*100)>49 then
  222.    'see if the letters work backwards
  223.     for i%%=0 to WordLength%%-1
  224.      if WG$(col%%+i%%,row%%+i%%)<>"" and WG$(col%%+i%%,row%%+i%%)<>mid$(WA$(cw%%),WordLength%%-i%%,1) then Failed_Reverse%%=True:I%%=WordLength%%+1:Result%%=FALSE else Failed_Reverse%%=false
  225.     next i%%
  226.  
  227.     if NOT failed_reverse%% then
  228.     'the word will work, write it to grid
  229.      Result%%=TRUE 'function will return success
  230.      for i%%=0 to WordLength%%-1
  231.       wg$(col%%+i%%,row%%+I%%)=mid$(Wa$(CW),wordlength%%-i%%,1)
  232.      next i%%
  233.     end if
  234.    else
  235.     Failed_reverse%%=true 'set due to not using reverse
  236.    end if
  237.  
  238.    if Failed_Reverse%% then 'try going forward
  239.     for i%%=0 to wordlength%%-1
  240.      if wg$(col%%+i%%,row%%+1)<>"" and wg$(col%%+i%%,row%%+1)<>mid$(wa$(cw%%),i%%+1,1) then result%%=FALSE:I%%=Wordlength%%+1 else Result%%=true
  241.     next i%%
  242.  
  243.     if result%%=true then
  244.      FOR i%% = 0 TO wLen - 1
  245.      wG$(col%% + i%%, row%%+1) = MID$(wa$(cw), i%% + 1, 1)
  246.      next i%%
  247.     end if
  248.   end if
  249.  case 2'Diagonal Up
  250.  'see if the word will even fit here
  251.   HorzLeftLen%%=CC%%-col%%
  252.   VertLeftLen%%=row%%
  253.   If VertLeftLen%%>HorzLeftLen%% then LeftLength%%=HorzLeftLen%% else LeftLength%%=VertLeftLen%%
  254.  
  255.   if WordLenght%%<=LeftLength%% then
  256.   'if the word fits
  257.    if AR%% and Int(Rnd*100)>49 then
  258.    'see if the letters work backwards
  259.     for i%%=0 to WordLength%%-1
  260.      if WG$(col%%+i%%,row%%-i%%)<>"" and WG$(col%%+i%%,row%%-i%%)<>mid$(WA$(cw%%),WordLength%%-i%%,1) then Failed_Reverse%%=True:I%%=WordLength%%+1:Result%%=FALSE else Failed_Reverse%%=false
  261.     next i%%
  262.  
  263.     if NOT failed_reverse%% then
  264.     'the word will work, write it to grid
  265.      Result%%=TRUE 'function will return success
  266.      for i%%=0 to WordLength%%-1
  267.       wg$(col%%+i%%,row%%-I%%)=mid$(Wa$(CW),wordlength%%-i%%,1)
  268.      next i%%
  269.     end if
  270.    else
  271.     Failed_reverse%%=true 'set due to not using reverse
  272.    end if
  273.  
  274.    if Failed_Reverse%% then 'try going forward
  275.     for i%%=0 to wordlength%%-1
  276.      if wg$(col%%+i%%,row%%-1)<>"" and wg$(col%%+i%%,row%%-1)<>mid$(wa$(cw%%),i%%+1,1) then result%%=FALSE:I%%=Wordlength%%+1 else Result%%=true
  277.     next i%%
  278.  
  279.     if result%%=true then
  280.      FOR i%% = 0 TO wLen - 1
  281.      wG$(col%% + i%%, row%%-1) = MID$(wa$(cw), i%% + 1, 1)
  282.      next i%%
  283.     end if
  284.   end if
  285.  
  286.  Diag_Fit=result%%
  287.  

The two arrays I am passing are both setup as strings and the Function is expecting 2 string arrays. But I must have something wrong.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Incorrect Array type passed to function error
« Reply #1 on: March 06, 2019, 08:14:59 pm »
The error line disappears when I do this

Code: QB64: [Select]
  1. 'DIM Grid(80, 60) AS STRING * 1
  2. DIM Grid(80, 60) AS STRING ' * 1
  3.  

but then another error pops up down the line.

So a fixed string array is different than variable length string array.
« Last Edit: March 06, 2019, 08:16:32 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Incorrect Array type passed to function error
« Reply #2 on: March 07, 2019, 09:25:35 am »
Here is stripped down version of problem:
Code: QB64: [Select]
  1. DIM fs(10) AS STRING * 1 'line 13 is fixed by commenting out * 1 on this line
  2. DIM vs(10) AS STRING
  3. FOR i = 0 TO 10
  4.     fs(i) = MID$("cobaltbblue", i + 1, 1)
  5.     vs(i) = MID$("cobaltbblue", i + 1, 1)
  6.  
  7. 'OK
  8. PRINT sPlus1$(vs(0))
  9. PRINT sPlus1$(fs(0))
  10.  
  11. PRINT sPlus2$(vs(), 0)
  12. PRINT sPlus2$(fs(), 0)
  13.  
  14.  
  15. 'this works
  16. FUNCTION sPlus1$ (s$)
  17.     sPlus1$ = CHR$(ASC(s$) + 1)  'EDIT this line
  18.  
  19. FUNCTION sPlus2$ (s() AS STRING, index)
  20.     sPlus2$ = CHR$(ASC(s(index)) + 1)
  21.  

Except for fixed record lengths and binary access of file info, are fixed strings needed for anything else?

Append: Oh yeah, if you want to use a string in a type definition but that was sort of fixed...
« Last Edit: March 07, 2019, 09:53:30 am by bplus »

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Incorrect Array type passed to function error
« Reply #3 on: March 07, 2019, 10:48:15 am »
Hi Cobalt - are you working with the text Screen 0 ?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Incorrect Array type passed to function error
« Reply #4 on: March 07, 2019, 12:50:32 pm »
Hi Cobalt - are you working with the text Screen 0 ?

Haven't decided. It will depend on just which way I find the Puzzle displays best.

Granted after becoming radioactive I only have a half-life!

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Incorrect Array type passed to function error
« Reply #5 on: March 07, 2019, 02:08:44 pm »
OK Thanks, reason I asked was the line

Dim Grid (80,60) as string * 1

Screen 0 would have them reversed no?

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Incorrect Array type passed to function error
« Reply #6 on: March 07, 2019, 08:05:44 pm »
OK Thanks, reason I asked was the line

Dim Grid (80,60) as string * 1

Screen 0 would have them reversed no?

No, Screen 0 is 80 wide(COL) and (normally) 25 tall(ROW). Now Locate would be reversed; LOCATE ROW, COL
Granted after becoming radioactive I only have a half-life!