Arrays... bug or misstake?

Get help using Construct 2

Post » Wed Oct 05, 2011 8:07 pm

I wanted to try out Arrays so I created a new blank project (r60). On the start of the layout I'm trying to create a array by first setting the size and then i have a sub-event with a For each XY element that sets the value at CurX and CurY to 10+Random(5)

The above seems to have no effect. Nothings happen. It seems like all values in the array is 0... I'm not even sure the For Each XY element part is running at all...

What am I doing wrong? Or are arrays bugged in R60?

My project:
http://dl.dropbox.com/u/44294994/room-test.capx
B
4
S
1
G
2
Posts: 14
Reputation: 1,328

Post » Fri Oct 07, 2011 12:31 am

I created an array for a path, but I didn't use CurX and CurY though. I just used a counter instead. I'm not sure on the best way to use CurX and CurY and CurValue.

http://www.scirra.com/forum/animate-player-sprite-movement-with-pathfinding_topic45001.html

B
20
S
9
G
2
Posts: 15
Reputation: 2,594

Post » Mon Oct 10, 2011 5:47 pm

I think I found the issue:

I was using random() when getting and setting values in the array... random returns a float value and it seems arrays accept them but then you just get weird or "blank" results... no errors or anything. It seems you have to keep this in mind when using arrays.
B
4
S
1
G
2
Posts: 14
Reputation: 1,328

Post » Mon Oct 10, 2011 5:51 pm

Forgot to add:
Mostly a actual error/crash of some kind is much better then silently ignoring a error. If array don't like float values for X, Y, Z I would much prefer if the runtime crashed when you try to use a float value. It's like creating a try/catch statement and then just leave the catch statement empty with no error handling = bad.

Edit: Ah, you CAN edit. :pTheLure2011-10-10 17:52:04
B
4
S
1
G
2
Posts: 14
Reputation: 1,328

Post » Mon Oct 10, 2011 7:17 pm

I fixed a bug with float values for array indices. However, in your project, the problem somehow seems to be that there are no instances of the Map array object. I suppose you deleted the layout you originally added the array to, but didn't delete the object type. Since it has no instances it essentially doesn't exist so you'll always get 0 for all the expressions on the object.

I'm not sure how to fix this! It seems to be an oversight in the editor. I'll see what I can do.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580


Return to How do I....?

Who is online

Users browsing this forum: armaldio, ETgirl79, Yahoo [Bot] and 22 guests