Simple or Harder?

Discussion and feedback on Construct 2

Post » Mon Dec 12, 2011 1:58 am

I have an array and Im creating a object (sprite) for each element of that array its fine but now I need to swap between to x values in other words I need to create that object in column 90 and the next at column 180 and the next at column 90 etc... How to do this easly with only one loop ?
Example:
the_x = 90
for each element in the array
{
   create(the_x, 100)
   if (the_x == 90) the_x = 180 else the_x = 90
}
or something like this
obs: I cant put this information on the array itself because Im using it to store de Text property....
Thanks in advance!Vinians2011-12-12 11:51:49
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
21
S
5
G
6
Posts: 166
Reputation: 4,885

Post » Mon Dec 12, 2011 3:09 am

Wow, not really sure what you mean. I can get that English is probably not your first language, but using some punctuation and more detailed explanations... might help others to understand what you want.

I'm also not sure what you mean by "each element of the array" unless you mean for each object (in the array), or maybe each column?

Best of luck.

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
45
S
17
G
37
Posts: 2,853
Reputation: 25,966

Post » Mon Dec 12, 2011 12:06 pm

Yes my friend, Im from Brasil. But forget the text and se at pseudo code, I replicate this algoritm in C2....
for each element in the array
{
   create_a_instance(objany, the_x, 100)
   if (the_x == 90) the_x = 180 else the_x = 90
}
Thanks
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
21
S
5
G
6
Posts: 166
Reputation: 4,885

Post » Mon Dec 12, 2011 1:41 pm

[code]
+ for "Y" from 0 to 9
++ for "X" from 0 to 1

> create object at 90+loopindex("X")*90, loopindex("Y")*100
[/code]

This will create 20 objects in two columns.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Mon Dec 12, 2011 3:37 pm

[QUOTE=Mipey] [code]
+ for "Y" from 0 to 9
++ for "X" from 0 to 1

> create object at 90+loopindex("X")*90, loopindex("Y")*100
[/code]

This will create 20 objects in two columns.[/QUOTE]
Hummm almost there but not yet... Se the picture below:

">
I need each the 40 to change to 180 on each iteraction of the loop.
1-40
2-180
3-40
4-180
But I needt to use this for..each loop above because the size of the array will be variable so I cant use your solution....
Help pls!Vinians2011-12-12 15:41:06
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
21
S
5
G
6
Posts: 166
Reputation: 4,885

Post » Mon Dec 12, 2011 3:46 pm

Create a local variable before your for loop and check it.
example
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Mon Dec 12, 2011 4:01 pm

Or use a conditional expression like: "loopindex%2=0 ? 40 : 180"

Example
Scirra Employee
B
129
S
45
G
15
Posts: 705
Reputation: 15,413

Post » Mon Dec 12, 2011 8:10 pm

Thanks a lot dudes its worked both!
I did not know of the existence of "conditional?" It's in the help of expressions?
Another thing, also did not know how to create a local variable in a group. Now that I found that just create a global variable and drag it to the group, logically it becomes "local" heheeh.
Be nice with others and with yourself!
My musics: https://soundcloud.com/vinians
My C2 Forum:
http://nmbr.forumeiros.com/
My Site:
http://www.dicasebytes.com.br
B
21
S
5
G
6
Posts: 166
Reputation: 4,885


Return to Construct 2 General

Who is online

Users browsing this forum: saiyadjin and 17 guests