Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / dudas con arrays

Author
Message
pamerco
11
Years of Service
User Offline
Joined: 2nd Jul 2012
Location:
Posted: 10th Jul 2012 19:29
good afternoon again.
I'm trying something like

Quote: "
type nivel
dim niv [5,6] as integer
numerodeprocesos as integer
numerodetoques_puzzle as integer
endtype
"

y luego defino esto
Quote: "
global dim niveles[200] as nivel
"


is that you can define multidimensional arrays, but I did not like.

can someone help me?

thanks
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 10th Jul 2012 21:07
In Tier 1, you may not put a dimmed thing inside a type. Sorry about that.

If you want that kind of flexibility, you need to use Tier 2.

You can make an array pretty much any number of dimensions you want.

But be very careful, if you redim an array with more than one dimension, you will probably lose data.

Cheers,
Ancient Lady
AGK Community Tester
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 10th Jul 2012 21:44 Edited at: 10th Jul 2012 22:14
This is one bad thing about Tier1, but there is a work around:



So to access the data, with 'f' being the object you're currently working on, you'd just use


with 'itemIntArray' would be the surrogate child object. They're two separate arrays, but as long as you address them with the same index variable ('f'), it's a workable solution. It's almost array equivalent of a flat-file database (instead of hierarchical, nested arrays).

Hi there. My name is Dug. I have just met you, and I love you.
pamerco
11
Years of Service
User Offline
Joined: 2nd Jul 2012
Location:
Posted: 10th Jul 2012 23:13
But finally I have done so ....



and then with the function of load level I did with my own editor


I could not even load levels, I have not had time but I think it should work well.
anwserman
12
Years of Service
User Offline
Joined: 20th May 2011
Location: Wisconsin
Posted: 11th Jul 2012 00:10 Edited at: 11th Jul 2012 00:14
This code here is wrong



These numbers create that many objects in the array, using a base-one counting system (you start counting at number one.) However, to access the objects in the array, you have to use a base-zero counting system (you start counting at number zero).

For instance. You want to store 200 objects in an array called 'foo'. You want each object to be set to the number 100. This code here would create it:


Your lower limit starts at 0. Your upper limit ends at 199. If you count from 0 to 199, you have 200 objects! It's just that the array is zero-based, but you defined with a one-based number (200).

So, for you, try:


This will give you space for 201 objects in your first dimension (0-200), 6 objects in your second dimension (0-5), 7 in your third dimension (0-6), and 3 in your fourth dimension (0-2).

I hope this helps you!

Hi there. My name is Dug. I have just met you, and I love you.
pamerco
11
Years of Service
User Offline
Joined: 2nd Jul 2012
Location:
Posted: 11th Jul 2012 16:14
thank you very much.
I always feel the same, I have a habit of working with arrays of 1 to limit it, depending on the language and I forget which is max-1 and are errors that can break your head then ... if the compiler does not warn you.

I managed exactly as you said. thank you very much
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 23rd Jul 2012 17:53
Actually, in Tier 1 (Basic), when you dim an array as 'dim x[10]', it actually creates 11 elements.

You can access it using indices from zero to ten.

When I code, I assume base zero and don't use the last index (10 in my example above), just to make sure I don't run into issues if/when I convert to Tier 2.

Cheers,
Ancient Lady
AGK Community Tester

Login to post a reply

Server time is: 2024-05-05 14:40:22
Your offset time is: 2024-05-05 14:40:22