Array Object use

For questions about using Classic.

Post » Thu May 06, 2010 6:02 am

I don't know if I'm just being dense, or if the structure and use of the Array Object is just really different to VB6 Arrays, but I just can't seem to do some basic stuff with it.

What I'm trying to do is to put 3 bits of information into an array, 1 set of 3 for each of 6 sprites. Then at another time and place in the game, loop through the array and compare the second element (2nd bit of information) of each record (set of 3 bits of information) and depending on what the 2nd bit of information is; increase the value of a private variable.

I can get the 1st and 2nd bits of information into the array, for the 1st sprite, but the 3rd bit overwrites the 1st bit or just messes up everything...I just can't seem to workout how to reference each element of an Array record - X,Y and Z.

I've been through the Wiki page for the Array Object, but alas here I am.

Can someone steer me in the right direction please...
B
4
G
3
Posts: 22
Reputation: 944

Post » Thu May 06, 2010 6:31 am

To use an array object like this you need to get and set the value at x, xy, and xyz.
Since you only have 6 items to track that shouldn't be too bad, but a huge array with all three dimensions could add a lot of memory, and processing.

You would then set up a loop to set x at loopindex, x,and y at loopindex, and x,y,and z at loopindex.
....Might want to take a look at the Ini object.
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Thu May 06, 2010 7:51 am

Thanks newt.

I had a look at the ini object and could use it, although I still think an array would be more efficient as the player is going to trigger the check at the end of each level, with new data.

Are there any tutorials or examples of using an array? I've had a quick look but alas I've not found anything yet.
B
4
G
3
Posts: 22
Reputation: 944

Post » Thu May 06, 2010 5:03 pm

Isn't there a bug in accessing the Z dimension for the array object?

As far as examples for arrays go. I use arrays in several places in Part 4 and Part 5 in the adventure tutorial. It shows how to loop through and read and write from X, and Y based on loopindex. I thought I ran into a bug when accessing Z, but maybe that was fixed.
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Thu May 06, 2010 9:46 pm

Thanks scidave, typical - I'd had a look up to Part 2 of the tutorial. I'll go and have a look at the rest.
B
4
G
3
Posts: 22
Reputation: 944

Post » Fri May 07, 2010 1:02 am

Hi. From my interpretation of the original post, it sounds as if you only need a 2-D array, like so:

x1y1, x1y2, x1y3,
x2y1, x2y2, x2y3,
x3y1 ...

Ok, so that may not be clear, but I made a simple example based upon what you described, and showing loops as well:

[url:qcxtus7x]http://dl.dropbox.com/u/5868916/arrayloop.cap[/url:qcxtus7x]
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Fri May 07, 2010 2:01 am

also, make sure you're using 1 indexing, and not 0 indexing, as you said you come from a visual basic background
1 is first in Construct, not 0, there is no 0 index
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Fri May 07, 2010 8:27 am

Thanks everyone.

I think I am now getting a handle on arrays following Silent Cacophony explanation :lol:
B
4
G
3
Posts: 22
Reputation: 944


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests