How do I make for-loop in event run only once

Get help using Construct 2

Post » Wed Oct 07, 2015 6:42 am

im using ajax to get data from a site, then i iterate this data into an array with a for loop.
as a sub event to the loop i call a function that populates a listbox from the data in array.
this works, but the function runs all the time.populating the listbox with thousands of duplicates.

how do i ensure the function is only called when my for loop is finished?
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Oct 07, 2015 7:33 am

easiest ways would be using a triggered event that is only called once..

Seeing as you use Ajax, using the Ajax on complete event sounds right..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Oct 07, 2015 9:40 am

my 'for' loop is a subevent to my ajax 'oncompleted' event.
B
9
S
2
Posts: 76
Reputation: 709

Post » Wed Oct 07, 2015 10:18 am

kaiko wrote:my 'for' loop is a subevent to my ajax 'oncompleted' event.


Could you share your events?
If The Ajax request is not done more than once, the "on completed" should only run once and as such all the attached subevents..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Oct 08, 2015 6:52 am

i found the error the subevent wasnt 'attached' properly in the event viewer
causing the sub-event to stand freely and run 60 times a second.
closing thread.
B
9
S
2
Posts: 76
Reputation: 709


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 32 guests