How do loops work?

In a blueprint I set a loop for repeating 256 times, I set the loop body to draw a thing in a different place every time and when completed it should print the word “Hello”

I first tried just executing the loop body, you know, skipping the loop itself so it should draw just one thing and it worked perfectly but now I execute the loop and it doesnt do the loop body.
In order for you to understand me look at this screenshot

223977-lol.png

Ajustar means set and aleatorio means random

So Thats how I set the loop. The loop body is not importan right now, as it just draws things in random places and as I said it worked perfectly when I dragged the execute line from beginplay to the SetVariable
But when I conected the loop it wont work

I understand that the first index is the number with wich the loop starts to count and the last index is when it stops looping
Loop body would be the part that should be repeated each loop and when its done it should print “Hello” but it just prints hello, it doesnt draw sprites anymore

I actually want the loop to be repeated 25600 times so that I fill a big map with things in random places, also the map is divided in 25600 sectors.

So the question is, am I doing something wrong? I mean the body loop part is good, it works but I surely have done something wrond with the loop.

PLEASE HELP

  1. Loop works perfectly =)
  2. Need see your code full.

Right now its look normal =)

  1. We need to see more code of that loop body to find a bug
  2. If you don’t want to break the loop you should just use " ForLoop"

I don’t say loops don’t work, I say I don’t know how to use them so here’s the “full” code:

The logic is as follows:

First of all I found that this code could be more efficient, I will add some changes later.

The map is a lanscape with a space full of stars texture with UVs, size: 1 square km, 100800 pixels by 100800 pixels, divided (in my imagination) in 16 sectors of 6300 pixels x 6300 pixels each, each divided in 10 microsectors in which a star system would generate

It first generates a random number between 0 and 2 which is the number of star systems generated inside each microsector. It then creates a star system placed in a random location in that microsector

The coordinates are set this way: each time the loop goes on (for a total of 25600 times, but I set it just to 256 to make it faster), it will divide the number of times it has already looped by 160 (the map is divided in 160 by 160 microsectors, again, 25600 total) The result integer is the row in which it is generated and the integer remainder, which is something between 0 and 159 is the column so it could be microsector 0-0 or 143-87
That will be useful for a coordinates system…

Each the result and the remainder are multiplied by 630 (length of a microsector) and are sumated with a random number between 0 and 630 and that sets the coordinates. For example if it is in the sector 65(column)-112(row), its coordinates will be x=40950 and y=70560 and z will always be equal to 110 for star systems.

This is a very early version of the code that only generates one kind of star in random places but I had to test it in order to continue.

Later on it will generate one kind of star of a list of 30 different stars each with its own graphics, with a random number of planets depending on the type of star, each planet with some properties and then I would start programming other things.

At first I just skipped the loop to see if the rest of the code worked. It indeed generated one star in a random place each time. Though I never seen 0 or 2 star systems being generated. I may put -1 to 3 as the range? I still don’t know how it works.

Anyways it worked until I conected the loop with the rest of the code. I will be trying things now

POSTED HERE CAUSE THE TEXT WAS TOO LARGE FOR A COMMENT

I will change that right now, thanks

EDIT: I changed the ForLoopWithBreak to a ForLoop, set the first index as 0, last as 2 and generated one system in a random position in the first sector. I will try more things

Completely demonstrated now, by experimenting I found I was right.
I think I should change the meta from self to something else.
I dont’ know how actor references work, maybe I have to create a new class or something I really don’t know xd but the meta needs to be different in each loop

EDIT: I think I should use SpawnActorFromClass but I don’t know what that class should look like.
Maybe I make the class generate some of those random caracteristics every system should have like tupe of star, number of planets etc…

your main error why it is not working is that you move the actor and not the component.

when you have columns and row its always good to use 2 for loops and seed your randoms to get some control over the result

Cool, I know now that I was actually moving the actor xd.
I don’t know what seeds are, I will look it up now, thank you!
Also how do you do the boxes?

Seeds: random uses a seed number to generate random looking numbers but as long as you use the same number as seed you get the same order of “random” numbers

Comment Box: when you press C you get a box around all selected nodes.

I really really thank you :smiley:
That’s super interesting
I changed the blueprint but I didn’t test it yet, I mean I tried but it was taking too long, I may change the 160 to just 4 for now to test it quickier.