hi. can anyone tell me the best practices syntax for creating and naming objects using a loop. it needs to all be in the main. like in the task listed, i want to just have a standard name, like "zerg" and then add a count number that increases. "zerg1, zerg2, etc" i tried referencing the counter i, but couldn't get it to work. i also created a separate variable that i referenced, but also that throws errors.
how to create and name objects using a loop
You must be signed in to leave a comment
16 May 2020, 18:22
Hi bob, if you're trying to look into quickly naming things without putting in work to do it for each and every one of them, there is a way. How I personally have done it is as such:You could definitely do whatever method works best for you, but as long as you incorporate some kind of counting system (or utilize the variable i) and add them to a string of some sort, you'll have a worry free system for naming. Hope this helps!
30 May 2020, 22:58
yes. i do understand your example, thank you, however, i was trying to utilize your technique in the naming of the, in your example, Zerg objects. in other words, i want to auto name them Zerg zerg1, Zerg zerg2, Zerg zerg3, etc. is that possible?
16 May 2020, 12:21
This is how you attach a name to an object.
16 May 2020, 12:20
Reset the code and then: Zerg zerg1 = new Zerg(); zerg1.name = "Joe";