Working with Array

Started by Hardcoal, February 25, 2020, 23:41:56

Previous topic - Next topic

Hardcoal

Hi, I have some questions about Arrays...

Im trying to work with Arrays and its a bit frustrating.. compared to TList.

For Example.. How can I clear Array?
How Can I tell Array Size?

Any Info about Arrays will be Nice

Thanks H.C
Code

ImJustAnotherCoder

#1
QuoteHow can I clear Array?

Strict

' Declare an array
Local a:int[]

' Assign data to an array
a = Int[1,2]

' Declare and assign an array
Local array:Int[] = [1,2,3,4]

' reassign the array data completely
array = [7,6,5,4,3,2,1]

' Clear and empty the array - puts it up for garbage collection
array = Null
' or assign to a new array with 5 entries initialized to default of 0
array = New Int[5]

' Just clear the array contents keeping its size the same
For Local i:Int = 0 Until array.length
    array[i] = 0
Next

The above fundamentals work the same for arrays of objects too.

QuoteHow Can I tell Array Size?

Local Length:int = array.length


QuoteAny Info about Arrays will be Nice
In the standard MaxIde editor menu go to Help-Home-Language[near the bottom of the page]-Arrays

Derron

https://blitzmax.org/docs/en/language/arrays

It misses an emphasized hint for ".length" and prefers to use "Len(arr)" in an example (the procedural interface way of requesting that information).


"Clearing out" - without assigning a NEW array requires iterating over it:


For local i:int = 0 until arr.length
  arr[i] = 0 'or Null for objects
Next



bye
Ron

Hardcoal

I was Trying to Redefine an Array Size.. im not sure its possible..

Ive Got an Image Say.. 600 on 400 pixels and I make an array of that Size..  Pixel[600,400]
then when I load a new image , i want to redefine this Pixel Array Size Again. Say.. 800 on 600 pixels.
Is it possible?
Code

Hardcoal

Ok, I Think i sorted it all out.. Thanks for the Help Guys
Code