Pablo1517
Pablo1517

Reputation: 73

Batch script looping through array and using values as parameters for exe

Hello there mighty stackers!

I have quite a problem, I need a batch script that will launch my game with a set of parameters (-something 1 -somethingelse 0 -language EN) and so on. Wait till it does some stuff and closes, after that I need to launch it again with different parameters and so it goes.

Basically I want my game to be launched few times with different language setting, and I would like to have all the languages in an array

set lang[0] = "EN"
set lang[1] = "DE"
...
set lang [n] = "..."

Then I want to loop over those values and basically launch the game with parameter -language put_array_values_here.

While I can program my own game, I never had to do windows scripts and I am completely green on that while actually having a little deadline :<

Can you guys help?

Upvotes: 1

Views: 179

Answers (2)

Monacraft
Monacraft

Reputation: 6630

Ok try this:

setlocal enabledelayedexpansion
:: Set number of languages:
set n=100

:: Set Values:
::: set "lang[0]=EN"
::: set "lang[1]=DE"
::: ...
::: set "lang[n]=..."

set "game=Game.exe -something 1 -somethingelse 0 -language "
:: Default game parameters ending in language and a trailing space

:: Loop to call all languages
for /l %%a in (0, 1, %n%) do (
%game%!lang[%%a]!
)

And that should do what you want.

Upvotes: 1

dbenham
dbenham

Reputation: 130819

I wouldn't mess with an array. Instead I would simply process a list using a simple FOR loop. Simply add one line within the parentheses for each language.

@echo off
for %%L in (
  EN
  DE
  etc.
) do yourGame.exe -language %%L

If you have a text file containing one language per line, then you could use FOR /F instead

@echo off
for /f %%L in (language.txt) do yourGame.exe -language %%L

Upvotes: 1

Related Questions