function + array problem

Blitz3D Forums/Blitz3D Beginners Area/function + array problem

gellyware(Posted 2003) [#1]
can you pass arrays into functions? im having a rough time with this


Dim spells  (100)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; spell images
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
spells(1) = LoadSprite ("particleImage4.bmp")


While Not KeyHit(1)
	If MouseDown (1) Then	createParticles ( spells(1) )


ok and in the function i have this:

Function createParticles (particle)
par.T_particle = New T_particle
		par\ent    = CopyEntity (particle)


basically i want to store spells in an Array, and pass the reference of the spell into the function so the function can copy the preloaded *spell*. Is this possible? I keep getting errors.


gellyware(Posted 2003) [#2]
got it :) i forgot to delete something in the beginning of the program and I didnt have debug enabled to see what it was. <--- noob


Oldefoxx(Posted 2003) [#3]
Arrays cannot be dimensioned in Functions in Blitz, so they have to be dimensioned within the main program. Hense, to use them directly in a Function, they have to be declared to be Global. That is particularly important if you need to reference the same Arrays in different Functions and in the main body of the program. By having them made Global, it is no longer necessary to try to pass them as Arrays -- you can now just pass an index reference into the Array so that the right element is being dealt with.

While it is likely possible to circumvent this limitation by several devices, there is little advantage in doing so. The less information that has to be passed as part of a Function call, the faster the calling process will be, even though it may be only a marginal improvement.


Koriolis(Posted 2003) [#4]
In fact arrays ARE globals, you have no choice (I mean the arrays you declare with Dim and use with '(' and ')', not the ones with '[' and ']'). And they can also be redimed in functions, you just need to declare them beforhand in the main program.


Almo(Posted 2004) [#5]
I'm trying to redim an array inside a function, and it's saying "Duplicate identifier"

If the array isn't declared outside in the main program, I get "Array not found in main program"

Weird.

Edit: got it figured out... when you redim, number of dimensions must be the same.


BlitzSupport(Posted 2004) [#6]

Edit: got it figured out... when you redim, number of dimensions must be the same.



I don't have Blitz handy right now to check, but this never used to be the case -- this at least used to work!

Dim Blah (0)

Function Oink (x)
    Dim Blah (x)
End Function

Oink (99)



_PJ_(Posted 2004) [#7]

Dim Blah (0)



You can Dim an array to 0?????????


Ross C(Posted 2004) [#8]
I think he means, mulitdimentions?

Dim Blah (0)

Function Oink (x,y)
    Dim Blah (x,y)
End Function

Oink (99,67)