For Loop Example

Chat about anything not covered in these forums, but keep it civil!

Post » Wed Sep 25, 2013 8:17 pm

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.    
B
4
Posts: 10
Reputation: 222

Post » Wed Sep 25, 2013 10:12 pm

more info and this should be on how do Isosensible2013-09-25 22:13:37
B
41
S
11
G
7
Posts: 514
Reputation: 9,706

Post » Thu Sep 26, 2013 5:10 am

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);
}
B
4
Posts: 10
Reputation: 222

Post » Thu Sep 26, 2013 5:34 am

Texbox doesn't have "append option" you should use writeable text or sprite font
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Thu Sep 26, 2013 6:11 am

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.
B
4
Posts: 10
Reputation: 222

Post » Thu Sep 26, 2013 10:23 am

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
B
94
S
33
G
118
Posts: 5,396
Reputation: 75,853

Post » Thu Sep 26, 2013 10:58 am

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
B
4
Posts: 10
Reputation: 222

Post » Tue Oct 01, 2013 6:16 am

Hi,
   How can i create a session with arrays?

Thanks
B
4
Posts: 10
Reputation: 222

Post » Tue Oct 01, 2013 12:09 pm

@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"?Jeff Skyrunner2013-10-01 12:10:40
I'm not a insane, my mother had me tested

I'm an engineer. To save time, just assume I'm never wrong
B
31
S
13
G
4
Posts: 141
Reputation: 4,857


Return to Open Topic

Who is online

Users browsing this forum: No registered users and 2 guests