[Solved] Why does 1 dimensional array pre-pad 10 zeros?

Get help using Construct 2

Post » Sun Mar 01, 2015 9:08 pm

My array starts off with zeros in the first 10 X slots. I'm not putting them in there. Why does this happen?
Last edited by locohost on Mon Mar 09, 2015 11:28 am, edited 1 time in total.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Sun Mar 01, 2015 9:57 pm

The array object defaults to a width of 10. Select it and look at the Properties window for the defaults.
ImageImageImage
B
71
S
21
G
211
Posts: 3,614
Reputation: 119,147

Post » Mon Mar 02, 2015 11:42 am

Yes I saw that. However, the first 10 positions are actually filled by default. So if you you array.push another value on the back, you're starting at position 11 and going forward. I thought perhaps that array.clear on create would do something but it doesn't.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Mon Mar 02, 2015 2:41 pm

Set size to (0,1,1)
ImageImageImage
B
71
S
21
G
211
Posts: 3,614
Reputation: 119,147

Post » Tue Mar 03, 2015 12:52 pm

That works? So the arrays will dynamically size as elements are pushed on the back? I'll give it a try.
B
13
S
4
Posts: 280
Reputation: 1,573

Post » Tue Mar 03, 2015 1:35 pm

locohost:
Yes, C2 arrays have dynamically size, you can change it any time you want with SetSize(w,h,d) action.
Default value for empty array is 'zero' - 0. So Array.Clear is smth. like to fill it with zeros.
Set width to 0 and push/pop/delete new values at any time.
B
8
S
1
Posts: 72
Reputation: 606


Return to How do I....?

Who is online

Users browsing this forum: Janaina and 3 guests