Array operations on structures.

Good morning everyone.

I have a problem in which I can not get it out:

-Make some mines that generate resources, multiplied, by two float and that this multiplication is added in a float every second in an arrays of structures.

In the code 1 it works and it is what I want to reproduce in the code 2, but I cannot make it work in an array of structure. Each element of this array is a mine and I want to go through each mine and do the same process as in code 1 on each element of the array and I can’t get it to do it.

Apart from this, I would like to show that float in a Text in the UI, but I still can’t get it. I plan to save the text, inside each mine, so that each one has its own UI text assigned to it.

I show you images of the cases.

If you think it is convenient to do it another way, I am open without problem. It may be that I am very focused on doing it this way, but it may be, that it is not the best.

Thank you very much to all of you.



Hey @BaBuuuuuu!

So the problem I think is the broken struct pin on your ForEachLoop!

Delete it and try doing it like this so you can reference each struct in the SetStructMembers node!

1 Like

Good morning @Mind-Brain .

Thank you very much for helping me first of all.

I have done it as you told me, but it does not do what I want.

In code 1, the result of the multiplication of the "Production- and “Worker” is added to the float “Total”. Every second this multiplication is reproduced again and added to the total, together with the previous operation. I leave some images of the result of code 1 and code 2 and I give you a written example as well.

Production: 5
Workers: 2
Total: 0

After one second:

Production: 5
Workers: 2
Total: 10

After another second:

Production: 5
Workers: 2
Total: 20

I would also like the total of each index in the array of structures to be reflected in the UI. For it I had thought of saving the text inside each index as a variable and to have each one its text saved inside.

I leave you the result of the operation in the code 1 that is how I want it to be. The result is 60 x 2 and it is added in the variable “Total”, 60x2 = total 120, pass one scond, 60x2 = total 240, etc. The red part is the result, the blue part the operation and in the green part, the entered data:

and the code 2 that repeats the operation every second, without accumulating in each operation, as you can see in the blue part that the result is always the same, the data of the index is in the green painted zone and yellow. The blue painted is the code. The operations instead should be in the first index 5x2 = total 10, pass one second, 5*2 = total 20, etc, and in the second index 40x1: total 40, pass one second, 40x1= total 80, etc. :

Thank you very much for the contribution! Hopefully we can solve it, because I’ve had this problem for almost 1 year.

Best regards.

Hey @BaBuuuuuu!

I went ahead and worked out the entire thing and tested it. This should be exactly what you need. Because it’s an array you have to replace the old version of the struct once the variables in the struct are set. Tested and works 100%

1 Like

Thank you so much @Mind-Brain ! You don’t know how long I’ve been waiting for this!! :slight_smile:.

Now I have also problems with displaying the variable “Total” in the UI. Do you know how I can make my UI text, write the result of one of my variables inside a structure arrays?
I tried to do this:

I have tried with a get, accessing the index and then the variable, but it doesn’t work for me.

I would also like to do operations, like for example to subtract in the variable “Total” one of the index of the list, when pressing a button. For them I would have to access to the Index of the mines, to be able to do it, it would be unnecessary to have to make a loop for them, because it would consume more resources I believe.

Thank you very much for everything. Best regards!

Hey again @BaBuuuuuu!

So you can get rid of that “Cast to Planet” node because planet is set, you can just attach it to the “Target” node. That’s what the “NOTE” on the cast is trying to tell you- it’ll save you a small amount of processing power.

Also, have you tried it this way?

As far as the operations, no, they shouldn’t be looped, you should specify what array element, and what value, then subtract the value from the previous value, set members of struct, then set struct. No loop! :slight_smile:

Hello @Mind-Brain !

Thank you first of all for continuing to help me!

I tried before publishing the post a break, but nothing like the structs member, but it still didn’t work. I leave you the sample:

I just made another simpler test, to put a text in the function, to see directly it is displayed, but no. Then there is something that I am skipping, but I do not know what it is. I show you in red where it would have to be changed.

I leave you the sample:

I also performed the operation of subtracting an amount in an index in the variable “Total”. It works, but it replaces the values of the index, then it does not continue adding, since it is all the values to 0 and I do not see a condition in which it does not change them, only that it subtracts the value that it wants of the index and that it continues adding. The operations that I want that it does always I show it to you in green and in red it is when the content of the vairable is subtracted, but for these operations with every second of execution of the game.

I send you a screenshot:

Thank you very much and a big hug. :slight_smile:

Hey again @BaBuuuuuu!

Let’s do one thing at a time, this is getting overly complicated for multiple problems at the same time. :slight_smile: Focus on one thing til it works! So here I’m going to start with the -10000 total set.

For this, you can’t cut corners with breaks, when you set the array element it has to be a combined struct.
Set Members in Mine Struct is not for getting pieces, it’s for setting. Drag off of the “Get” A REF make sure it’s not a get COPY because the copy won’t save. Maybe go ahead and delete the “Get” you have with index 0 and redo it making sure it’s a reference not a copy. Drag off that and break it to get the total, it should not have the white line as it is a “Get.” THEN do the -1000, “Set Members In MineStruct” and plug that into the new total, then off of that you should have the combined struct come out for the set array Elem node! Like I did in the example above. :slight_smile:

1 Like

Hello @Mind-Brain !.

You are absolutely right :sweat_smile:. I completely forgot, that in set members, you could select which variable to make visible, to select “Total”. I put the result in case someone can use it:

What I don’t know, is why the Total, of the structure, is not displayed to me in the UI and neither the text that I put as an example, as if something was not working, I don’t understand why.

Thank you very much for your contributions, I am learning a lot and taking giant steps in these structures with arrays.

A greeting.

1 Like

No worries, @BaBuuuuuu! That’s the best thing to hear, that you’re learning!

Now you can drag off of “Set members in MinesStruct” and use your “Set Array Elem” to set the new total. Just don’t break it and you should be fine!

After that, you should be able to get A COPY for your UI use! Remember, with arrays:

Get a COPY - for just getting info
Get a REF - for changing info

:slight_smile:

Hello everyone and @Mind-Brain !

In the end, I have made a custom loop, to have more control over my list and to be able to manage it better. I leave you an image:

The problem is that now when I perform the operation that I mark in orange, I want that result if it exceeds or equals a number that I set in the index of my list in a variable, that operation is cut in that index. For example:

  • My operation is 2 * 5 every second, I set it as limit 17, when it goes by 15 and the next second it is 20, before it is shown in my total variable, can I tell it to be 17 so that it never exceeds that number?

I have tried several times with a branch, but it doesn’t work.

Probably it is a nonsense, but I do not find a node that helps me.

I await your answer.

Thank you!

Hey again @BaBuuuuuu!

You can simply use a Clamp (Float), if I’m understanding this correctly!

Then you can set a minimum and maximum for a float coming through! If it’s higher than the max it sticks to the max, if it’s lower than the minimum it sticks to the minimum!

Hope this works for you! :slight_smile:

Wonderful, it was exactly what I needed, as always thank you very much @Mind-Brain , you are a phenomenon!

A hug. :smiley:

1 Like