Why A.at(x,y) is zero after SET A.at(x,y)=1?

Discussion and feedback on Construct 2

Post » Tue Nov 22, 2011 8:28 pm

I'm trying to program a labrynth creator routine. Doing it by means of events is quite complicated for me.

After changing the code to debug it, I tested with this lines at "System - On Start of Layout":

MyArray Set size to (4,2,1)
MyArray Set value at(0,0) to 0
[... more MyArray() initialization ...]
MyArray Set value at(2,1) to 1
TextBox Set text to ""&MyArray.At(2,1)

TextBox displays "0".

Should I wait a frame or something before MyArray gets the value?

How can I wait until I'm sure all values have propagated through the matrix?
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Tue Nov 22, 2011 8:31 pm

Are you sure the array is big enough to hold all the values? Values written outside the array have no effect and retrieving a value outside the array returns zero.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Tue Nov 22, 2011 8:34 pm

arcalaus, do you have a capx you can post? It might be easier to help if we can see the code.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Tue Nov 22, 2011 9:44 pm

OK, here's the Capx:

http://www.apagada.com/varios/labe3.capx

The array is called Direcciones (instead of MyArray), and it is supposed to store X and Y delta values for East, South, West and North.
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Tue Nov 22, 2011 10:21 pm

Good luck with this! I have always been interested in procedural generation - this seems like a difficult but worthy endeavour!
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Tue Nov 22, 2011 10:34 pm

I was having a hard time working with your capx so I pulled out the important parts (i hope).

Here is an example i came up with:

Direcciones Example

I hope that helps!
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Tue Nov 22, 2011 10:43 pm

There are no instances of that array object on your layout. When there are no instances the expressions default to 0. The only solution at this point is to delete the Direcciones object from the "object types" folder and create a new array on the layout.

@Ashley
This situation is pretty easy to reproduce.
1. Create Array.
2. Delete Array from objects bar.
At this point Array only exists in the "object types" folder, and there is no way to add an instance of it to the layout.

Could a solution be to allow dragging Array from the "object types" folder onto the layout if there were no instances of it already there?
B
79
S
24
G
54
Posts: 4,738
Reputation: 40,739

Post » Wed Nov 23, 2011 12:44 am

Good catch, r0j0hound! Wastrel2011-11-25 12:37:00
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Wed Nov 23, 2011 9:42 pm

I swear I tried adding arrays to layout, but they refused to appear on it. I'll give another try.
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Post » Wed Nov 23, 2011 10:06 pm

Just in case someone else makes the same mistake...

Since moving non-world objects to layout seems to be impossible, i've edited the layout.xml file in order to avoid events being deleted during object deletion.


I've edited the "nonworld-instances" part of layout.xml and added:

[code]
<nonworld-instances>
<instance type="Direcciones">
    <properties>
      <width>4</width>
      <height>2</height>
      <depth>1</depth>
    </properties>
</instance>
</nonworld-instances>
[/code]
...It worked!
Now, I'll focus in the labyrinth generation routine
(it seems that making a javascript "behaviour" would be easier, though).
B
39
S
11
G
5
Posts: 132
Reputation: 8,228

Next

Return to Construct 2 General

Who is online

Users browsing this forum: fredriksthlm, MilkGames, shinichild and 13 guests