is it possible to put a "for loop with break" into a function ?

I’m trying to construct a function which includes tasks of verifying if an input value match a list of values contained in an array of reference values. I tought a STOP LOOP WITH BREAK was the good thing to do so.

However to stop the loop I have to trigger a custom event function linked to a previously created custom event when the match is reached. But this custom event can be created only in the EVENT GRAPH not inside the inner function definition GRAPH.

Is it possible to include a for loop with break in a function definition ?

To verify if a value is in an array, do a “for each loop with break” and use it to check if array element = your input. Then branch and on true, link to break.
If you create a custom event in event graph, you can call it in a function by doing right click and typing the name of the function.

You could instead create a macro, since those can have multiple in/out execs.

Or you could just have your the event set a bool that cuts it off inside the function with a branch.

Thanks for the answer… To be more precise here are screen capture of the loop (the loop it self is a function definition TAb)


The custom event which should fire the HALT order has been defined in the EVENT GRAPH of the same BP.


The loop itself works fine … But I whished to halt it as soon as the match was reached. Which does not occur…

According to the BP reference doc I should link the break pin of the loop node to the custom event… But it is not possible to do so because inside the function definition graph the custom event node itself is not available (Only the call of a function linked to it).

If you want to fire “stop boucle” when you break, you have to link your true branch to break and link “stop boucle” to completed. But you have to set a bool to know if you have to fire it or not too !

Edit : On true you set a bool “true” and link to break. On completed you check it, on true you set it false and fire your event.

Edit : You can try to fire your event in true branch node too and then link to break and from completed output link to next node too. This would save the bool part.

Thanks … I will try it

Thanks Fen … It worked (But it seems the custom event is even not necessary anymore). Below is the loop that works…


But could you be more explicit when you say " …]and link “stop boucle” to completed. ". Is the "stop boucle " to be linked the function call or the event itself ?

I thought that your event boucle had something in that you needed to fire when break, not that you wanted to use it to do the break. And as the loop with break does the job, you no more need it. My bad ^^
But the added bool is needed because if you loop and that there is no match, next part will be fired on completed.

Edit : Or on branch true you do the related event to true and then link to break, or you set a bool to know that it has been true, link to break and on completed you fire you event and reset your bool.

Edit 2 : As you use index, you may have to save it too when you set your bool on branch true to have it on completed.

Thanks Fen and Zeustiak … Fen I will study the case you speak of (maybe I would need it some day).

Following the remarks from Fen, here is a solution which should work (note : the variable “stop_boucle_1” is set to value 0 at start of the function - not shown on picture) :


Note : It works - verified because later in the execution of the function I can print the ID (index) and position of the element that matches the array data.

Guys, I may have misunderstood, but the “contains” function on the array would do the job just fine wouldn’t it ? It seems you can’t access the index of the result element though, but I don’t know if that’s important in your script.

Yes … in this case its important… the aim is to get the identity and position of the clicked piece (if any) on a chessboard. Because afterward one must check if the piece can be played (which side can play), then to calculate the possibles moves (according to the piece type) , etc…

To know only that there exists a match is not enough here…

Of course I’m a beginner … and there may be some more efficient methods to do this … If someone has a better way, I’m eager to ear and learn.