More Efficient Way to Code This? [Resolved]

I’m trying to set up a function that can work for multiple different sets of arrays and variables that are uniformly named but only the first word is changed in each. Is there a way to make this more efficiently where somehow I could do something like

set {BlockType}PropsHealth = for (Manipulator : {BlockType}PropManipulators) do {BlockType}Health

This is the current code:

PopulateBlocks(BlockType : string) : void = 
            if (BlockType = "Coal"):
                set CoalPropsHealth = for (Manipulator : CoalPropManipulators) do CoalHealth
            else if (BlockType = "Stone"):
                set StonePropsHealth = for (Manipulator : StonePropManipulators) do StoneHealth

The name of this post indicates that your issue is resolved. Could you please share your solution for others who may have the same question?

One more efficient way to do this would be to use a Case instead of if…else if… blocks.

1 Like

I can’t remember what I ended up using. I think I tried to use maps instead but ran into issues with containers inside of editable maps not working. I think in the end I just created arrays for each type and associated each type to an index.