Arrays as a type field

Blitz3D Forums/Blitz3D Beginners Area/Arrays as a type field

Tau_Aquilae(Posted 2012) [#1]
It's been a while...

Is it possible for a type to store an array as one of it's fields, I haven't really messed with arrays in blitz much (although I've done it quite often in Java)

Here's what I'm trying to do:

I have a custom type called "Class" Each class has a name as a string, an ability (as an ability type) and two "legal" slots, one as a weapon type and one as an equipment type. I want to have these two be arrays of each custom type.

Basically these arrays tells what weapons/equipment are legal for each class. So if a player tries to equip an infantryman with a magic staff, or a scout with power armor a function that will check these arrays will stop the player from doing such a thing.

So is there anything special i need to do to define the field as an array? or do I define it normally?

Last edited 2012


Yasha(Posted 2012) [#2]
As follows:

Type Class
    Field name$, ab.Ability
    Field legal1.Weapon[W_SIZE], legal2.Equip[E_SIZE]
End Type


In other words, as normal but with the array size following the declaration. The size of the array must be a compile-time constant.


Floyd(Posted 2012) [#3]
The documentation for this is hidden inside the description of Dim.
Scroll down until you see *NEW* BLITZ ARRAYS *NEW*.

The main differences from regular arrays are that they must be one dimensional and size must be a constant.

There is one other quirk, which was probably not intentional. You can declare these arrays to be of various types, such as

Local a#[10]

for an array of floats. But afterward you must not use the type tag:

Print a[5]
Print a#[5]

The first example, with a[5] is correct, while the second is an error.


Yasha(Posted 2012) [#4]
TBH the second one should be an error. Appending type tags in the middle of expression statements is both ugly and actively unnecessary ("actively" as in "the only thing you can potentially achieve is get it wrong and cause an error").


Tau_Aquilae(Posted 2012) [#5]
That's a HUGE help thanks!