Jump to content
  • Advertisement
Sign in to follow this  
Gallivan

Incrementing Variable Name

This topic is 4164 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible in Python for a variable to be stated on one line and increment? Pseudo-code: User Input = x x = 4 VariableCreated%s %(x)= 0 List VariableCreated Output ------ Variable1 Variable2 Variable3 Variable4 I have tried it this way, and I know I'm doing it wrong. However, I have not the slightest clue as to what this may be called and as such I can't Google my problem. Any help you have would be hugely appreciated. :)

Share this post


Link to post
Share on other sites
Advertisement

It depends. The term would be "metaprogramming", a very advanced topic, BUT... Chances are that's not what you *really* need to do. It's just the only way you know of, so far, to represent what you're thinking of. My guess is what you really need is a list. You need to store multiple values, the amount of which won't be known until run-time, and then access them by their number, correct?

Share this post


Link to post
Share on other sites
I have no idea what that pseudocode is trying to do. Could you explain what you're trying to achieve, rather than how you're trying to achieve it? Are you trying to create a set of predictably named variables from within the code? And if so, why not just use a list or a dictionary?

Share this post


Link to post
Share on other sites
Similiar to my other topic (I think it's right underneath if you need to reference), I'm trying to create tiles with names as [0 - 0], [0 - 1], etc.

These will also act as variables which will hold a simple sentence such as Forest, River, etc. So I need to create a set amount of these "tile variables" once the user generates their map-size.

I will read up on lists after school today, thanks. :)

EDIT: I didn't really adress the first reply. I believe that's exactly what I need to do. :D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!