0

I'm trying to replace stat.score and stat.level with corresponding variables, but it just prints stat.score=000099 to every line.

Here's the code:

@echo off
mode con cols=100 lines=40
setlocal EnableDelayedExpansion
:GameRender
del %cd%\assets\GameRender\pets\cthulhu\GameRender.txt
set "stat.score=000099"
set "stat.level=0"
set "Render_Ln=0"

for /L %%a in (1,1,39) do (

if !Render_Ln! EQU 39 goto :pause
set /a "Render_Ln=!Render_Ln!+1"

for /f "usebackq delims=@ skip=1" %%g in ("%cd%\assets\GameRender\pets\cthulhu\GameRender_source.txt") do set Line=%%g
echo:!Line! | findstr "stat."
    if %errorlevel% EQU 0 (
        set Line=%Line:stat.score=!stat.score!%
    )
echo:!Line!>>"%cd%\assets\GameRender\pets\cthulhu\GameRender.txt"
)
:pause
pause
for %%a in (%cd%\assets\GameRender\pets\cthulhu\GameRender.txt) do type %%a 
pause>nul

And here is GameRender_source.txt.

  • Debugging your batch files – DavidPostill Jun 25 '16 at 21:22
  • Just looking at your formatting, without testing your code... I noticed that you are using a piping method for "do set ... | ...". Try this instead; do (newline ... ... ... newline) instead. It might help? Also try printing to screen Line to see if you are grabbing what you think you are. – ejbytes Jun 25 '16 at 23:52
  • Apply Delayed Expansion consistently e.g. in if %errorlevel% EQU 0 (. Moreover, think about set Line=%Line:stat.score=!stat.score!% command (I'd try call set "Line=%%Line:stat.score=!stat.score!%%" or call :someproc where the :someproc subroutine might be something like set "Line=!Line:stat.score=%stat.score%!"&exit /b) – JosefZ Jun 26 '16 at 10:44
1

Another option is to use a PowerShell script to replace the values; the script should be somewhat self-explanatory:

(Get-Content d:\GameRender.txt) | ForEach-Object {$_ -replace "stat.score", "000099" -replace "stat.level", "0"} | Set
-Content d:\GameRender.txt
| improve this answer | |
0

Okey so I was able to solve this with your assistance by changing the GameRender_source.txt content to be only on 1 line.

for /f "usebackq delims=@" %%a in ("%cd%\assets\GameRender\pets\cthulhu\GameRender_source.txt") do set Render=%%a
call set "Render=%%Render:stat.score=!stat.score!%%"
call set "Render=%%Render:stat.level=!stat.level!%%"
echo:!Render!>>"%cd%\assets\GameRender\pets\cthulhu\GameRender.txt"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.