❔ How do I name an object after a variable in that object?
I have a class with a variable called "name", how would i make "name" the name of the object?
17 Replies
Objects don't have "names"
What you can have is a field/property in the object which is a string which is the name
eg.
i dont really understand
i am trying to recusrively create objects based off of user input
im not sure what to put between Item and =
what is
items
?a list of all items
the code works if i put a random variable name, but it will only work once
not variable, object
Well, you'll need a loop in you want to enter multiple items
yeah this is in a loop
oh shit
it does work
yeah
haha
my bad
When you declare a variable, that variable is local to the current scope, in this case your loop. After an iteration of the loop has finished, the variable is "deleted" and is redeclared on the next iteration.
ok i understand
There is no such thing as variables building up over the course of a loop
thanks a lot haha
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.