start of layout + For each

Get help using Construct 2

Post » Tue Feb 25, 2014 11:50 am

I have variable_1 = 0. On start of layout I create 2 arrays. From on start of layout there is a subevent: For each object(array) do variable_1=variable_1+1. Debug says I have 3 arrays, why value of variable_1=1 and not 3? The same happens when instead of subevent I call function after creating arrays. Function has on call - subevent(For each array do variable_1=variable_1+1).
B
4
Posts: 17
Reputation: 232

Post » Tue Feb 25, 2014 4:20 pm

Post your code for best chance of help.
B
71
S
21
G
230
Posts: 3,687
Reputation: 128,845

Post » Wed Feb 26, 2014 8:37 am

Image
Image
(Pic has been cut Right click to see full)

Additional questions:
1. How do I write

Example 1:
If (condition 1)
{
do 1
If(condition 2)
{
do 2
}
}

Example 2: (This is what happening and I want the logic to work as Example 1)
If (condition 1)
{

If(condition 2)
{
do 2
}
do 1
}

2. How can I see code "written" in Construct in text editor?
B
4
Posts: 17
Reputation: 232

Post » Wed Feb 26, 2014 10:39 am

Hello T4U,

Last things first, you can't see the code ever from within c2 environment (as much as I know, that is). Maybe it's possible to view it from outside, after it's been changed to html5, but I'm not sure about it either. And in time you actually notice what you do inside c2 is the code and you forget the need to see it. I know because I came from XNA and currently I don't find anything I can't do with it. (Except 3d and per pixel data read on sprites, which is actually possible and has been done in C2, it's just that "I" can't do it.)

The code you want is pretty easy, though;

While a condition is selected press "b" to create a sub event. Then do it one more time, thus you would have two sub events.
In the first sub event enter condition 1 and do whatever you want
In the second sub event, press x first to make it an "else" event, then enter your condition 2.
You can repeat the process as much as you want. This is actually an if-else if chain statment.

See you around :)
B
18
S
4
G
1
Posts: 332
Reputation: 3,149

Post » Wed Feb 26, 2014 12:28 pm

To the original question(with pics): Any idea why variable_1=1 and not 3?



About the logic I truly hate it. I know what I want to write but the use of it is so difficult. Maybe I will get used to it but for now <angry face>. It would be nice if there was set of 10-20 code-logic pictures along with Statement it checks.
B
4
Posts: 17
Reputation: 232

Post » Wed Feb 26, 2014 2:17 pm

If you take the for each out of the sub event and just have it as a separate event

so it becomes something like

start of layout....(set up as before)

(separate event)
if variable1=0
for each array -- set variable1 to variable1+1

do you get the right answer ?

(not checked)
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Wed Feb 26, 2014 2:30 pm

You have 3 arrays, the one already on the layout, and the two newly created. As to why your variable equals 1, it's simple : Iteration only occurs on objects that are available on the top level condition. So using RamPackWobble suggestion should do the trick !
Last edited by Magistross on Wed Feb 26, 2014 2:38 pm, edited 1 time in total.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Wed Feb 26, 2014 2:36 pm

You don't need the For each. Array.Count will give you the number of array objects. Do you really need to create dynamic instances of arrays? If now, adding them on the layout will probably be easier.
B
71
S
21
G
230
Posts: 3,687
Reputation: 128,845

Post » Wed Feb 26, 2014 3:44 pm

RamPackWobble:
It does the trick if you add trigger once.

Magistross:
What do you mean by "on the top level condition"? Where is the problem in my thinking. I am creating array before I call For each, so why newly created arrays are not counted?

blackhornet:
I am aware of the fact that you can use Array.Count. This topic is spawn child of another problem. I planned to use "for each object" for selecting instances as the construct logic for picking up instances is strange for me. Btw adding things on layout is noobish + I will need my object to do "On created events".
B
4
Posts: 17
Reputation: 232

Post » Wed Feb 26, 2014 4:05 pm

Ok - been playing.

Image
gives
Image

but, to be honest, I can't see why gvCountBlue2 is different ?
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests