Page 1 of 1

emptying an array

Posted: Wed Sep 01, 2004 2:57 am
by AfterDeath
I have an array, that gets populated throughout my script. I want to be able to "erase" the array (size goes back to 0 (empty) or -1 (non-existant)). How can I either delete or "empty" my array?

Note: it would not be looping through it setting it to 0 or "".

Thanks!

thing

Posted: Wed Sep 01, 2004 3:16 am
by tltrude
Hard to say without seeing the array thread, but you could do this.

$mything[0] remove
$mything[1] remove
$mything[2] remove
$mything[3] remove

or

$mything[0] delete
$mything[1] delete
etc...

or maybe this would work

$mything remove

Posted: Wed Sep 01, 2004 3:46 am
by AfterDeath
Alright. Being that the array size is unknown... should the following work?

Code: Select all

while ($myarray.size > 0)
    $myarray remove


Thanks!

Posted: Wed Sep 01, 2004 4:03 am
by tltrude
Hmmm, it is not looking hopeful.

Types of arrays
---------------

1) Constant array
Created by expression of the form entry_1::entry_2::entry_3:: ... :: entry_n
Constant arrays start their indexing at 1.
Once created a constant array can not be changed but it can be read for its values.

2) Hash table array
Unitialised entries evaluate to NIL. Any new entry can be set.

3) Targetname array
Created by the $ targetname operator if more than one entity exists for that targetname.
For example, $player is an array if more than one player is in the game.
Targetname arrays start their indexing at 1.

Posted: Wed Sep 01, 2004 12:40 pm
by jv_map
You can simply do

local.myarray = NIL

:)

Re: emptying an array

Posted: Wed Sep 01, 2004 2:33 pm
by Bjarne BZR
AfterDeath wrote:I have an array, that gets populated throughout my script. I want to be able to "erase" the array (size goes back to 0 (empty) or -1 (non-existant)). How can I either delete or "empty" my array?

Note: it would not be looping through it setting it to 0 or "".

Thanks!
Do you just need it for reuse, or does it contain a number of script_object's that you have spawned and now need to delete?

If you explain what you are trying to do, we may be able to give better help...

Posted: Sat Sep 04, 2004 12:03 am
by AfterDeath
The array is used to store a "stack" of messages that will be printed every X seconds. I need to be able to clear the array, so that only new text can be printed. I hope I make sense.