Keeping track of resources

I’m working on a RTS in which the player has to collect resources and build/make things. but i’m having trouble figuring out how to keep track of resources. Should i use a for, for each loop or something else?

That is an incredibly broad question. Firstly what exactly do you mean by “track resources” are you talking about for each players gathered resources? or resources on the map?

for players, I would simply use a basic storage structure (probably just a dictionary of type. the each time a resource is gathered or spent, the value would be amended as such (eg ResourceStore[“Gold”] += 100;)

as for how to track resources remaining in the map? well that depends far too much on the structure of your levels and game to be generalized in this simple post.

but if you can provide a more detailed description of your needs it might help.