Can't Dim an array inside a Function?
Blitz3D Forums/Blitz3D Beginners Area/Can't Dim an array inside a Function?
| ||
| In Blitz3D do all arrays have to be created inside the main part of the program? I just tried to create one in a function and it said array doesn't exist? |
| ||
| standard arrays are always global. You can define "Blitz Arrays" inside a function. Just define them as a local variable and use square brackets. EG: Local TempArray[100] It's an undocumented command, but it's unlikely to be removed because many, many people use them. Check here for more of an explanation: http://www.blitzcoder.com/cgi-bin/code/code_showentry.pl?id=thechange09052002191420&comments=no |
| ||
| Thanks ! |
| ||
You can use standard arrays inside funtions if you first initialise the array 'outside' in the main loop:Dim a(0) ; <- initialise array a()
testdim
k$=Input$("Press RETURN to end ...")
End
Function testdim()
Dim a(5)
a(1)=50 : Print a(1)
End Function
|
| ||
| Yeah I realised arrays are global, just wanted a way to make and delete one inside a function though for resource-efficiency. |