emptying an array

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
AfterDeath
Corporal
Posts: 26
Joined: Fri Apr 09, 2004 4:34 am
Contact:

emptying an array

Post 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!
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

thing

Post 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
Tom Trude,

Image
AfterDeath
Corporal
Posts: 26
Joined: Fri Apr 09, 2004 4:34 am
Contact:

Post by AfterDeath »

Alright. Being that the array size is unknown... should the following work?

Code: Select all

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


Thanks!
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Post 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.
Tom Trude,

Image
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

You can simply do

local.myarray = NIL

:)
Image
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Re: emptying an array

Post 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...
Admin .MAP Forums
Image
Head above heels.
AfterDeath
Corporal
Posts: 26
Joined: Fri Apr 09, 2004 4:34 am
Contact:

Post 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.
Post Reply