Working with Arrays

Need some help with that macro you're working on or aren't quite sure how to get your macro to do something? Ask here!

Moderator: MacroQuest Developers

TI994a
a ghoul
a ghoul
Posts: 87
Joined: Mon Oct 13, 2003 12:25 pm

Working with Arrays

Post by TI994a » Thu Nov 20, 2003 11:51 am

Few questions here for the gurus...

First, var scopes are local or global for simple vars. Arrays are simply declared to be arrays, but no scope is defined. Are arrays global in scope, or only in scope to the declaring sub?

Second, the documentation doesn't show any functions dealing specifically with arrays. Are there any hidden functions that return the size (element count) of an array, or is this something one has to keep up with manually in code?

Third, is there a way to "delete" or "resize" arrays in the MQ macro language?

I'm trying to understand all the ins and outs of arrays as best I can.

- TI

Scrime
a ghoul
a ghoul
Posts: 86
Joined: Sun Sep 21, 2003 5:48 pm
Contact:

Post by Scrime » Thu Nov 20, 2003 12:26 pm

afaik, arrays (and timers) are global. I dont know of any way to make them local.

As to the other two questions, I don't know. I always keep track of my array sizes manually.
[url=http://www.catb.org/~esr/faqs/smart-questions.html]asking smart questions[/url]

Mckorr
Developer
Developer
Posts: 2326
Joined: Fri Oct 18, 2002 1:16 pm
Location: Texas

Post by Mckorr » Thu Nov 20, 2003 12:38 pm

Arrays can only be declared as array or array2, one dimensional or two dimensional. They are global by definition.

I don't believe there is code to determine the size of an array, but it's a decent idea. Something along the lines of $sizeof(@MyArray). It would just have to read through the array one element at a time, increment a counter, and return when it gets to an undefined element. A little more complex for two dimensional arrays, but not overly so.

Since we don't delcare an array size, there's no reason to resize them. Might want to think about adding a /cleararray command, a subset of /zapvars maybe.