October 16, 2021, 07:43:52

Author Topic: Working with Array  (Read 693 times)

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 743
  • nothing is personal
Working with Array
« on: February 25, 2020, 23:41:56 »
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
...

Offline ImJustAnotherCoder

  • Jr. Member
  • **
  • Posts: 22
Re: Working with Array
« Reply #1 on: February 26, 2020, 04:04:51 »
Quote
How can I clear Array?
Code: [Select]
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.

Quote
How Can I tell Array Size?
Code: [Select]
Local Length:int = array.length

Quote
Any Info about Arrays will be Nice
In the standard MaxIde editor menu go to Help-Home-Language[near the bottom of the page]-Arrays
« Last Edit: February 26, 2020, 04:24:01 by ImJustAnotherCoder »

Offline Derron

  • Hero Member
  • *****
  • Posts: 3661
Re: Working with Array
« Reply #2 on: February 26, 2020, 06:10:03 »
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:

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


bye
Ron

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 743
  • nothing is personal
Re: Working with Array
« Reply #3 on: February 26, 2020, 19:10:12 »
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?
...

Offline Hardcoal

  • Hero Member
  • *****
  • Posts: 743
  • nothing is personal
Re: Working with Array
« Reply #4 on: February 26, 2020, 23:01:13 »
Ok, I Think i sorted it all out.. Thanks for the Help Guys
...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal