How do I Use loopindex in a sub-event

Get help using Construct 2

Post » Mon Feb 08, 2016 11:22 pm

Hi All,

I'm having some trouble on a game i'm working on where the loopindex is always -1. I've got a repeat function set up to repeat 100 times and on the 100th iteration I want it to perform an action, the problem is that although this loop is running I've found that setting a text object to the current loopindex just seems to say "-1". Does anybody know if there is a way to get around this?

This is how i've got it set up.
Image

And this is how its displayed (note the -1 which is my text object)

Image

I've also tried setting loopindex to a local variable, but that doesn't seem to work either.
B
4
Posts: 4
Reputation: 208

Post » Mon Feb 08, 2016 11:35 pm

if you instead loopindex ... compare Fader.Opacity>0 ?
Image
B
62
S
23
G
7
Posts: 1,470
Reputation: 10,731

Post » Mon Feb 08, 2016 11:35 pm

Loopindex starts at 0, so if you repeat 100 times your loopindex will only ever get to 99. So change your code to compare to 99 instead of 100
Last edited by thatserafimkid on Mon Feb 08, 2016 11:39 pm, edited 1 time in total.
B
32
S
8
G
2
Posts: 100
Reputation: 2,610

Post » Mon Feb 08, 2016 11:37 pm

Try changing the "repeat" by "for"
for "x" from 0 to 100

>>>>set text to loopindex("x")
B
6
S
1
Posts: 29
Reputation: 465

Post » Mon Feb 08, 2016 11:41 pm

The problem is the Wait breaks the logic. The code won't hold the loopindex value, as it's a global value. Use a Timer to do this.
ImageImageImage
B
71
S
21
G
204
Posts: 3,586
Reputation: 115,576

Post » Mon Feb 08, 2016 11:42 pm

Still nothing

Image

The text now says 0 instead of -1 now though
B
4
Posts: 4
Reputation: 208

Post » Mon Feb 08, 2016 11:43 pm

blackhornet wrote:The problem is the Wait breaks the logic. The code won't hold the loopindex value, as it's a global value. Use a Timer to do this.


How would I use a timer in this scenario?
B
4
Posts: 4
Reputation: 208

Post » Mon Feb 08, 2016 11:52 pm

Image
B
32
S
8
G
2
Posts: 100
Reputation: 2,610

Post » Mon Feb 08, 2016 11:54 pm

if you instead loopindex ... compare Fader.Opacity>0 ?

Image
Image
B
62
S
23
G
7
Posts: 1,470
Reputation: 10,731

Post » Tue Feb 09, 2016 12:05 am

thatserafimkid wrote:Image


That worked perfect, thanks ever so much :D
Image
B
4
Posts: 4
Reputation: 208


Return to How do I....?

Who is online

Users browsing this forum: ColombageEnPLS, Yahoo [Bot] and 5 guests