1.

Solve : More for loop troubles?

Answer»

So I was writing a game for fun, and I ran into a for loop problem where it isn't saving %%G into a veriable that I can call. Nor is it reading the full file. Any Idea's?

cities\Buy.bat
Code: [Select]:: %gotoc% = Tipa
:: %vender% = Paxto
setlocal EnableDelayedExpantion


:start
cls
cd %gotoc%\%vender%

for /f %%G in (stock.cur) do (
set vender.item.G=%%G
cd ..
cd ..
cd ..
cd Products
cd %%G
for /f %%G in (Cities.cur) do (
if %%G EQU %gotoc% goto ok
)
Echo ERROR
pause >nul
exit
:ok
for /f "tokens=2 delims==" %%G in ('findstr "%gotoc%" Value.cur') do (
set value=%%G
)
cd %~pd0\%gotoc%\%vender%
echo !vender.item.G!=!value! >>vender.tmp
echo !vender.item.G!
)

echo.
echo Which Item Would You like to Purchase
set /p item=
if %item% EQU "BACK" goto back.to.city

....
cities\Tipa\Paxto\stock.cur
Code: [Select]Fish
Sugar
Products\Fish\Cities.cur
Code: [Select]Tipa
Alexandria
Bastion
Jui
Products\Fish\Value.cur
Code: [Select]Tipa=1
Alexandria=3
Bastion=9
Jui=1

All I'm getting is:
Code: [Select]!vender.item.G!

Which Item Would You like to Purchase


** The .cur files are being treated like .txt
(wrote the files in notepad and used 'rename *.txt *.cur' in cmd)Quote

Expantion

That's not how you spell 'expansion' ...



There is ALSO an issue where %%G is the outer loop VARIABLE and you are reusing %%G in the inner loops. It's wiser to use %%H %%J %%K etc in the inner loops.There is yet another issue: you can't have labels inside loops. As far as the command interpreter is concerned, the INTERIOR of a loop is one long line, and you cannot have a label in a line of code. This is one good reason why the undocumented, unsupported practice of using a double colon to start comment lines is frowned upon. It will break a loop.

And 'vendor' has only one 'e'.






Discussion

No Comment Found