Access each element of array one after the another using foreachloop?

Hello I am trying to control an actor from a string. What i am doing is I get the character array from the string and process each movement control string character and change the location of the actor using timeline.
But the problem is while using foreachloop in blueprint all the characters are executed simultaneously and there is complete haphazard in the movement.

I have attached two snapshot showing the issue? Plz help me out!!

When are you calling StartBotMove ?
I would recommend waiting on a action to be done before checking for the next.

Yes because a tick is just several milliseconds, it is too fast. You want to go trough one letter and do an action, wait for it to finish and then go through the second letter.
And then you must clear the text otherwise you would just reread it the next tick.

I am calling StartBotMove event from Event tick of level blueprint and passing the complete string(i.e “FLFLFRB”) character array to the event.

I tried to adding the delay block in between the foreachloop and first branch , but in that case it just skips the whole check process and produces no movement.

You shouldn’t have to, it will loop only when the current is finished but if you are using function that animated your character (make him move at a certain speed) then you need to be sure that the function will call the next thing only when finished.
Otherwise the move function will start being executed and directly call the next which will (I think) override the first one etc and this could be your issue.

I have taken care of that… Such that the Tick Event is called only once… so this is no problem.
Further that is the question… that how do i wait between the consecutive array elements??

You could try having a variable storing the index he must execute as long as it is not the next he waits and when the first is over then it increments the value by one.

You would just need to wait for the loop array index to be equal to the variable’s stored index.

The first screenshot is unreadable so it is hard to look everywhere. Could you take a screenshot of the first letter path for example ?
Because I am looking to reproduce the problem to see if the foreach loop is bugging.

Well for animating the character i am using timeline as you could see… and in timeline basically i am just updating the rotation and location values… So i don’t think i need to make sure of the overlapping or such… but in this case it is overlapping as all the time line are being called concurrently.

How do i ensure that the previous execution has been finished and process the next character. As i have mentioned earlier i have tried using the delay function but in that case it just waits for mentioned time and then animate all the actions in a instant.
It seems to me like there is some kind of fixed time in which the execution of foreachloop is being done and if delay is applied then it just gives the end value in one instance.

That could be done ultimately, but whats the problem with foreachloop is what i wanted to know?

I tried using the for loop and same thing happened again… -_-

I can’t manage to replicate that issue…
When you set a break point and go step by step what happens ?

You have an infinite loop because your condition is always true here.
1 <= LENGTH but 1 is never incremented.

(and you always get the 0rd element)

I tried doing it while loop… and the play mode terminated with an error showing that occurrence of infinite loop detected. Now i am helpless how to do it in other way?
I am posting the snap of the script as well.

-_-
I am not that fool sir…
I have incremented the i value once the execution of timeline is finished… It is not visible in the snap

  1. What is your desired outcome? I’m a little confused about what you want it to do. A foreach loop traditionally will happen in order but all immediately following each other, not over multiple frames. If you want it to do all the Bs then all the Ls then all the Rs you will have to store a variable to compare against and once you are done with the Bs you will trigger an event to set the new variable from B to L.

  2. You should use a switch instead of a bunch of nested ifs.

I didn’t mean it that way I was just being careful. Something is clearly wrong but I don’t see it. You need to debug step by step and look why the condition never changes.

The problem is that your timeline doesn’t happen while you loop. What it is doing is that it is looping infinitely because i won’t get incremented until the timeline has a chance to Tick. The loop doesn’t wait for the timeline to finish to move on.

The timeline can’t tick until the loop is finished, and the loop can’t finish until the timeline ticks.

edit: If you put a breakpoint in your loop and a breakpoint in your timeline you’ll see what I mean.