How do I get the same result from this function?

Get help using Construct 2

Post » Fri Sep 12, 2014 8:47 pm

I was working on this function for creating a object called beast box which is a 40x40 square image that gets repeated 40 times. I'm using a loop and a array with a width of 10 and a height of 4 to achieve this.

When I call the function the first time I get the results I want. As seen in image 2.png

I want to destroy the boxes and recreate them each time the menu is opened. So I had the menu destroy the beast_box object when closed.

The problem is when I open the menu a second time the boxes are created and stacked on top of each other 40 times. (see 3.png All in the top left corner instead of being spaced out in neat rows. What am I doing wrong here?
You do not have the required permissions to view the files attached to this post.
B
15
S
4
Posts: 31
Reputation: 1,267

Post » Fri Sep 12, 2014 9:43 pm

The problem is that beast_box.width and beast_box.height will return 0 when no beast_box object exists. Presumably the first time you have one beast_box outside the layout so it works then after you destroy them all it no longer works.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Fri Sep 12, 2014 9:58 pm

I put a create object line in the function and it fixed my issue! Thank you very much :D
B
15
S
4
Posts: 31
Reputation: 1,267

Post » Fri Sep 12, 2014 10:08 pm

You could also solve the problem by setting the position after creating the object:
Create object beast_box at (0,0)
Set position to ...
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 24 guests