Forcing a loop on a key press?

Get help using Construct 2

Post » Mon Jan 09, 2012 9:48 pm

Hi,

I'm used to coding languages rather than drag and drop. Being a total noob at this, I'm stuck at a simple thing! How to press say key "Q" (an event) and make the resulting action loop round an array. I understand the Array aspect, been doing them for years. My problem is that the Loops are part of the System "Event" and are not an "Action".

So how do I then make a loop happen?

I'm assuming there's ways to create functions?

Looked at the Array Tut but he simply prints hello word 10 times using an system loop event.

Any help appreciated.

Iain
B
2
G
1
Posts: 6
Reputation: 912

Post » Mon Jan 09, 2012 10:21 pm

Hello Iain.
Quick practical answer:
You'd have to launch your loop as a sub event of the "Key press" event.

Now for a bit more explanation:
It highly depends on the context and what you are trying to achieve.

I'd suggest you to have a look at how events work if you're still (understandably) struggling with this concept.
You can also check more about the loops in C2 as they are part of the system references.

As I said earlier, it depends a lot on the context of what you are trying to do. If you could explain a bit more what is the purpose of your loop and even provide a Capx, it would help us help you ^^
I hope the few manual articles already enlightened a bit your way though.

As for functions. Tricky question again ^^
There is no built-in way to reproduce functions as you know them in coding language.
Nevertheless you can use groups act on their activeness and use Global variable as parameters.
Another solution, closer to what you are used to, is to use the custom plugin function.

Here, I hope this provides some answers already.
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: 7,000
Reputation: 57,795

Post » Mon Jan 09, 2012 10:25 pm

Hmmm.. is a sub-event my solution? I program Objective C, Game maker (usually all coded via GML), Java and outwitted by a GUI based language.   
B
2
G
1
Posts: 6
Reputation: 912

Post » Mon Jan 09, 2012 10:32 pm

This blog article will describe C2's architecture better than I could ever do.
I hope it might be a useful read to you too.
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: 7,000
Reputation: 57,795

Post » Mon Jan 09, 2012 10:45 pm

Thanks for swift reply. Sub-event worked a treat. I'm just trying to create a 2D array (x/y grid) and and place sprites based on the number in the array. A map editor grid type idea.

Have been trying to work my way through Tuts/Docs but am finding they are skipping over some small nuggets of info I need (or actual "code" examples). Construct Classic had full game Tuts that was making it easier to understand. Saying that, the samples that come with Construct 2 are pretty good.

Thanks againsinofnature2012-01-09 22:52:52
B
2
G
1
Posts: 6
Reputation: 912

Post » Mon Jan 09, 2012 11:27 pm

"2D array to place sprites" I did something like that in cc
Basically I use only one sprite, with different animation frame which are the object I want to place.
so I just have to do something like :
[code]Global variable rows=10 //number of rows for the level grid
Global variable cols=10 //number of columns for the level grid
Global variable cellSize = 32 // size of the cells
System: Start of layout
System: for "" from 0 to rows*cols-1
    -> System: Create Sprite on layer 0 at ((loopindex%cols)*cellsize,floor(loopindex/cols)*cellsize)
    -> Sprite: set animation frame to Array.at(loopindex)[/code]
You don't really need 2D arrays. If you know the number of columns for each rows you can pretty much count each cells from top left to bottom right.Yann2012-01-09 23:28:09
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Jan 10, 2012 8:08 am

Thanks, thats close to what I ended up with though you did answer another noob question that I was going to ask. I was puzzled how to get the current value of the for loop (I ended up using a local variable) but I see its as easy as using loopindex.    I'm too used to using:

for n = 1 to 10 so you'd use n to determine position.

Liking the one sprite and using heaps of frames trick by the way. That may work quite nicely for what I'm trying myself.

Thanks for the info. This is all part of the fun of learning a new language/tool.   
B
2
G
1
Posts: 6
Reputation: 912


Return to How do I....?

Who is online

Users browsing this forum: h1k3 and 18 guests