Array Bugs
Blitz3D Forums/Blitz3D Programming/Array Bugs
| ||
Does anyone know why this would not work. function HI(dim array(3)) ;causes error return array(3) ;returning arrays doesnt work end function are these even real arrays? or just a function, shouldnt arrays be like this dim array[3] = 0,0,0 |
| ||
No, they look like this:dim array(3) array(0) = 0 array(1) = 0 array(2) = 0 Function HI(toReturn) Return toReturn EndFunction Note: That I think is C++ |
| ||
how do u post a *code* with green letters and black into your post? do you do something like this "<code> HI </code>" I wish you could Return arrays and use them in functions, it makes me a bit mad. |
| ||
function HI(dim array(3)) Is this the function delcaration? Or do you mean to call the function HI with that array element as the parameter? Then you need to do : HI(dim array(3)) That should work I guess... The "function" keyword should only be used for declaring the function. and yes, use <code></code> but with square brackets [] |
| ||
EDIT: LOL, the second time in two minutes that somebody is faster with posting than me :P {code} Here the code {/code} But replace {} with []: Here the code |
| ||
lol tried to get there first :) |
| ||
This information can be found in the BlitzBasic Language Reference. Arrays Arrays are created using the standard BASIC 'Dim' statement, and may be of any number of dimensions. For example: Dim arr(10)Creates a one dimensional array called 'arr' with 11 elements numbered 0...10. Arrays may be of any basic type, or a custom type. The type of an array is specified using a type tag. For example: Dim Deltas#(100)Creates an array called 'Deltas' of 101 floating point elements. If the type tag is omitted, the array defaults to an integer array. An array may be dimensioned at more than one point in a program, each time an array is dimensioned, it's previous contents are discarded. Arrays may be dimensioned inside functions, but a corresponding 'Dim' statement of the same array must also appear somewhere in the main program. For example: Dim test(0,0) Function Setup( x,y ) Dim test(x,y) End FunctionYou will also find other important information on the Language's Syntax in the Reference as well. |
| ||
But, you can do 'Blitz arrays' that look like this: Local a[20] referenced like this: a[10] = 45 and passed to functions like this: Local a[20] a[12] = 400 Print blah (a) Print a[10] WaitKey End Function blah(c[20]) c[10] = 45 Return c[12] End FunctionYou can also store them in Type objects. |