BlitzArray problem

Blitz3D Forums/Blitz3D Beginners Area/BlitzArray problem

fetcher(Posted 2008) [#1]
I get a variable type mismatch at profile$[count] = file$ when trying to run this.

Function Sign_in()

   Local profile$[5]

   dircheck = ReadDir(CurrentDir$())
   count = 1
   Repeat
      file$ = NextFile$(dircheck)
      If Instr(file$,".pro") Then 
         profile$[count] =file$
         count = count + 1
      End If

      If file$ = "" Then Exit
   Forever
End Function


Can BlitzArrays not be Strings, or have I made some other mistake?


KillerX(Posted 2008) [#2]
First, use brackets.
Second, use
 Dim 



fetcher(Posted 2008) [#3]
You can't use Dim inside a function. I'm trying to avoid making this a global array.


Cp(Posted 2008) [#4]
You dont have to make it global, just put it at the beginning of the program.
Its automatically able to be used anywhere.


Floyd(Posted 2008) [#5]
I don't know why, but you must omit the type specifier when you use the Blitz array, i.e.

         profile[count] =file$



fetcher(Posted 2008) [#6]
Cp: What then is the difference between declaring it as global as opposed to not?

Floyd: I no longer get the error once I remove the $. However, when I try to print the contents of profile[x] I just get a zero instead of a file name. Did I miss something else?

Function Sign_in()

   Local profile[5]

   dircheck = ReadDir(CurrentDir$())
   count = 1
   Repeat
      file$ = NextFile$(dircheck)
      If Instr(file$,".pro") Then 
         profile[count] =file$
         count = count + 1
      End If

      If file$ = "" Then Exit
   Forever

   For x = 1 To count
      Print profile[count]
   Next
End Function



Cp(Posted 2008) [#7]
put the dim command at the beginning of the file, with all the global vars.
you dont need to flag it as global, as you can already use it anywhere in the program + if you do use dim GLOBAL ISN'T ALLOWED.At least for me.


fetcher(Posted 2008) [#8]
I understand what you are saying. I was trying to avoid having a bunch of arrays declared at the top of the program by declaring them locally inside a function. Since profile[x] isn't used anywhere else in the program I wanted to keep it contained in the one function that does use it.

I was under the impression that it was bad practice to have arrays declared at the top of the program if they are not going to be used throughout it. Is this false?


Snarkbait(Posted 2008) [#9]
Use the '$' when you declare the array, just not when you reference it later - it works, try it...

poop

Function poop()
Local a$[10]
a[1] = "Hello"

Print a[1]
End Function 



fetcher(Posted 2008) [#10]
Works like a charm Snarkbait. That is the last thing I would have thought of. How does that make any sense?

Thanks for your help everyone.


Snarkbait(Posted 2008) [#11]
It does not make sense.... BlitzArrays were kinda hacked in there long after B3d had been released.