Page 1 of 2
pass an array to a procedure
Posted: Sat Apr 16, 2005 11:51 pm
by doodlemunch
how do i pass an array to a procedure? i want to access all the float numbers i got in an array how can i pass the array to the procedure? i tried with @value at the procedure values but it gave me an error when trying to compile
Posted: Sun Apr 17, 2005 12:06 am
by Xombie
Is this to a dll? Because otherwise, all arrays are global in PB. You can just access it like normal within your procedure. No need to pass anything.
Posted: Sun Apr 17, 2005 12:09 am
by doodlemunch
i have an array with 4 values, they are color values (r,g,b etc). floats.
i have a procedure which needs the array to be passed because inside the procedure i call a dll which needs the array info (the colors).
i cant seem to pass the array correctly. my color is taken as green although what im sending is red.. and even if i have 0,0,0 its green anyway, i think im sending the pointer or something. how can i work arround this? is it even possible? how can i "fake" the array to the dll if not?
thanks!!!!
Posted: Sun Apr 17, 2005 12:22 am
by doodlemunch
I did it !!!

thanks anyway !
Posted: Sun Apr 17, 2005 12:23 am
by traumatic
I don't know if I got your question right but maybe this helps (?)
Code: Select all
Procedure showArray(*array.l)
For i=0 To 10
Debug PeekB(*array) ; PeekW(), PeekL(), PeekF()
*array+1 ; +2, +4
Next
EndProcedure
Dim myArray.b(10)
For i=0 To 10
myArray(i) = Random($FF)
Next
For i=0 To 10
Debug myArray(i)
Next
showArray(@myArray())
I guess there will be more elegant ways for sure...
EDIT: Ah... too late again... didn't see your last response.

Posted: Sun Apr 17, 2005 12:31 am
by doodlemunch
but if I use a for then I must call the dll function many times? this wont work!
and i managed to make it work but somehow it might be sending integers or something because i cant seem to mix the values, if i send 1,0,0 i get full red, thats ok ! but if i send 0.1,0,0 i still get full red! weird!!! if i send 0.1,0.1,0.5 i dont get a blueish color at all, its white!.
this is like what im doing:
Code: Select all
;my array
Dim Color.f(4)
Color(0) = R.f
Color(1) = G.f
Color(2) = b.f
Color(3) = 0.0
;this is my function
Procedure MyFunction(*value.f )
Dim TempArray.f(4)
TempArray() = *value.f
CallFunctionFast(*thefunction, TempArray() )
EndProcedure
;now im calling my function
MyFunction( Color() )
Posted: Sun Apr 17, 2005 12:37 am
by traumatic
Now that I see what you're up to, why don't you simply pass the pointer on?
I mean, an array is nothing else than an "easy to handle memoryarea".
BTW: You're working with pointers here, a pointer can't be a float.
It should be MyFunction(*value.l).
Posted: Sun Apr 17, 2005 12:37 am
by doodlemunch
Posted: Sun Apr 17, 2005 12:38 am
by doodlemunch
oh didnt see your post.
if i do that will the values remain floats and be passed like floats and everyone will be happy? (ill go test).
edit: no it doesnt work still

Posted: Sun Apr 17, 2005 2:12 am
by doodlemunch
can someone help me with this?
Posted: Sun Apr 17, 2005 10:48 pm
by srod
Are you sure the colour array you are using should be 'float' types?
I only ask because colours are normally represented by 'long' datatypes.
I'm probably barking up the wrong tree completely!
Posted: Sun Apr 17, 2005 11:05 pm
by traumatic
doodlemunch:
What DLL is that you're using?
Does it work outside your procedure, like
Code: Select all
CallFunctionFast(*thefunction, @yourArray())
?
If it does, it should also work like this from your procedure:
Code: Select all
Procedure MyFunction(*colorArray.l )
CallFunctionFast(*thefunction, *colorArray)
EndProcedure
There's no need to copy the values to a new array.
srod wrote:I only ask because colours are normally represented by 'long' datatypes.
Hmm... last time I checked, OpenGL and DirectX were considered 'normal'.
Both are using floats as color-values

SCNR

Posted: Sun Apr 17, 2005 11:22 pm
by srod
Ah, not a great one for graphics me! Was talking with experience of PB and basic GDI only. Just making sure the problem was nothing obvious; usually is in my case!
I second your comments about the arrays and their being no need to copy the elements across to a new array etc.
Posted: Sun Apr 17, 2005 11:25 pm
by traumatic
srod wrote:Just making sure the problem was nothing obvious; usually is in my case!
You know I justed wanted to banter you about this

Posted: Sun Apr 17, 2005 11:35 pm
by srod
I consider myself well and truly 'bantered' on that score!
