0

I'm really new to Batch and I was trying to make a game where you place "landscapes" kind of thing. But I ended up using a lot of variables:

set a1=%none%
set a2=%none%
set a3=%none%
set a4=%none%
set a5=%none%
set a6=%none%
set a7=%none%
set a8=%none%
set a9=%none%
set a10=%none%
set a11=%none%
set a12=%none%

I wanted the user to input what "kind" of landscape, lets say "b. So:

set a1=%b%
set a2=%b%
set a3=%b%
set a4=%b%
set a5=%b%
set a6=%b%
set a7=%b%
set a8=%b%
set a9=%b%
set a10=%b%
set a11=%b%
set a12=%b%

And ecetera but after a while it got really long. Is there a more efficient way of assigning so many variables? Any help would be great.

Kumquat
  • 52
  • 9
  • 2
    `For /l %%C in (1,1,12) Do Set a%%C=%b%` –  Jul 21 '17 at 17:41
  • 2
    `FOR /L %%# IN (1,1,12) DO SET "a%%#=%b%"`…but why set all of those variables to exactly the same value? – Compo Jul 21 '17 at 17:59
  • @compo I set them to all the same variables so that it would look like tiles and when the player moved to that spot, I would set that tile (like a1) to %player%. – Kumquat Jul 21 '17 at 18:48

1 Answers1

-1

I really cannot tell what you are doing from the way your question is posed, But you may be able to accomplish your task via a for loop, or possibly from a text file: "Set Variables From Text File".

Basically, there is no good way of asking a user to input a ton of variables especially if all of these are actually unique values. If you are just asking a question and then checking the answer then your best solution is to use a loop and reuse the variable (unless you want to track the answers historically).

The best solution is to not use a batch file and divert your focus to a more powerful scripting language like PowerShell, or Python. If you are sticking with Windows specifically, you can get some mileage out of PowerShell. If you are looking to learn something used on multiple platforms Python is the way to go (at least in my line of work).

Benjamin McGill
  • 359
  • 3
  • 5