Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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 ?

    #2
    Hello,
    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.

    Comment


      #3
      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.
      Map Generator 1.0
      Map Generator 2.0
      Map Generator 3.0

      Comment


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

        Click image for larger version

Name:	loop.jpg
Views:	1
Size:	38.0 KB
ID:	1072144

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

        Click image for larger version

Name:	cust_event.JPG
Views:	1
Size:	19.6 KB
ID:	1072145

        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).

        Comment


          #5
          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.
          Last edited by Fen; 04-08-2015, 06:56 AM.

          Comment


            #6
            Thanks ... I will try it

            Comment


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

              Click image for larger version

Name:	loop2.JPG
Views:	1
Size:	62.4 KB
ID:	1072147

              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 ?

              Comment


                #8
                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.
                Last edited by Fen; 04-08-2015, 07:31 AM.

                Comment


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

                  Comment


                    #10
                    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) :

                    Click image for larger version

Name:	loop3.JPG
Views:	1
Size:	88.3 KB
ID:	1072152


                    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.
                    Last edited by Vasquehaal; 04-08-2015, 11:49 AM.

                    Comment


                      #11
                      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.

                      Comment


                        #12
                        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.
                        Last edited by Vasquehaal; 04-09-2015, 05:02 AM.

                        Comment

                        Working...
                        X