Forcing a loop on a key press?

0 favourites
  • 7 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • 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

  • 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.

  • 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.   <img src="smileys/smiley17.gif" border="0" align="middle" />

  • 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.

  • 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 again

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • "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 :

    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)

    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.

  • 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. <img src="smileys/smiley1.gif" border="0" align="middle" />   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.   <img src="smileys/smiley1.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)