For Loop Example

0 favourites
  • 11 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • I am trying a simple for loop example in construct 2?If any one can help ?

    Thanks.

    I created a for ""from i to 10    Textbox set text to i

                                      System Add 1 to i

                                      System stop loop.

    But the loop is not breaking after reaching 10.

    Where did i go wrong.

    Thanks in advance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • more info and this should be on how do I

  • I just want to see the loop starting from 0 and ending 9 and i should see the 9 in the textbox at the end.

    for(i=0;i<10;i++)

    {

    printf(i);

    }

  • Texbox doesn't have "append option" you should use writeable text or sprite font

  • I understood that joan.But i just need to rotate the loop for 10 times and stop and i am not able to do that can u help me if u have any idea.Because i am not able to upload the screen shot.

  • Hello,

    For this:

    for(i=0;i<10;i++)

    {

    printf(i);

    }

    The equivalent in C2 would be this:

    for "" from 0 to 9    

    ----Textbox set text to loopindex

    Or if you want a named loop variable:

    for "i" from 0 to 9    

    ----Textbox set text to loopindex("i")

    Lastly your initial event setup in your first post would look like this in c:

    int i;

    for(int loopindex=i; loopindex<=10; ++loopindex)

    {

    ++i;

    break;

    }

    -cheers

  • Hound thanks. One more thing i want to know is i have a string and i am trying to getting the values to array the string is some thing like this

    tempString={what is ur name?,option1,option2,option3,option4,answer,what is ur name?,option1,option2,option3,option4,answer,what is ur name?,option1,option2,option3,option4,answer

    }

    Now i want store this in an array and show one after the other on the screen.

    Can you please guide how can i store all the 3 questions and answers and after a right or wrong answer i will i have another question.

    Please help me

  • Hi,

       How can i create a session with arrays?

    Thanks

  • kiran

    To do it quickly with arrays, I would use a bidimensional array:

    A[0,0] = "What is your name?"

    A[0,1] = Option 1

    A[0,2] = Option 2

    A[0,3] = Option 3

    A[1,0] = Second question

    A[1,1] = Option 1

    A[1,2] = Option 2

    A[1,3] = Option 3

    A[2,0] = Third question

    A[2,1] = Option 1

    A[2,2] = Option 2

    A[2,3] = Option 3

    And so on.

    To move from one question to another, it depends on how you will implement the game.

    What do you mean with "a session with arrays"?

  • hello, i was deal with this question,beacause i find the 'for' of c2 don't auto stop loop.you need use a global variable as index,then every loopindex to the index.and set a height limit.

    hope you know my answers.

  • sorry,i back again,i don't know my answer,it said me don't have authority...

    i hava a new way for the question.

    our game is every tick flash,so the 'for' is every tick runing, we can control enter of the 'for'.

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