I am currently trying to learn c++ because i want to make blueprint functions in c++ to use in my blueprints.
I have managed to create a function with the right inputs i need and outputs needed but i am at a lost on how to do this because it uses two loops to make a grid and checks if the grid is centered.
Here is the blueprints, I just don’t know the best way to do this as all the guides i watch dont cover a loop in a loop or using two different ints to loop and then make vectors
Based on your Blueprint function, the C++ function should be declared as such in your header file:
void CalculateProceduralGrid(bool Condition, int Row, int Column, float CellSize, FVector& WorldLocation, FVector2D& RelativeLocation, FVector2D& GridCoords);
This is under the assumption that you still need that boolean parameter, Condition. In the hopes to not do all of the work for you, and that you will be able to take away some knowledge, here is the basic framework of the function but with some of the aspects from the Blueprint function missing so that you can fill in the rest. (I have confirmed that the following code compiles on UE 4.25.4):
Depending on the value of Condition, you will do a nested for loop on Row and Column (typically it is common practice to use ‘i’ and ‘j’ in cases of nested loops, but feel free to name these variables something more descriptive if you need). Within the second for loop, we set the GridCoords to FVector2D(i, j); which essentially instantiates an FVector2D using those values. Seeing as in your Blueprint, you do this regardless of whether Condition is True or False, I too have done this here.
Now its up to you to do the remaining of the function; that is calculating and returning WorldLocation and RelativeLocation. I hope this helps and serves as a stepping stone for you to complete the function Good luck!