So there is some problem in this code, its probably just some punctuation error that I haven't noticed yet but for some reason I cant find it.
I read that this is how to do a loop with Do
then the number of times, in this case '%dmg%
', tell me if this wasn't true.
I do have parts that define the variables;
set dmgt=0
set /a wl=1000*%upts%/%epts%
and I do have all of the others set.
Using the pause command I found this is the problem;
if %upts%*%utroop% LEQ %epts%*%etroopt% ( goto fail
) else ( set /a dmg=%wl%*%etroop%/1000
set /a dmgt=%dmg%+%dmgt%
do %dmg%
SET /A type=%RANDOM% * 3 / 32768 + 1
if %type% == 1 ( if %snip% GEQ 1 ( set /a dmg=%dmg%-1
set /a snip=%snip%-1
)
)
if %type% == 2 ( if %mgs% GEQ 1 ( set /a dmg=%dmg%-2
set /a mgs=%mgs%-1
)
)
if %type% == 3 ( if %rif% GEQ 1 ( set /a dmg=%dmg%-1
set /a rif=%rif%-1
)
)
enddo
)
if %upts%*%utroop% LEQ %epts%*%etroopt%
does not calculate the value of each side, it strings togetherthe contants of upts
*the contents of utroop
and compares that string against the RHS. You need to explicitly calculate the two values into variables using aSET
.Your
ELSE
clause invokes a "block statement" that is, the ENTIRE contents of the parenthesised series of statements up to the closing)
followingenddo
. Batch parses the statement from theIF
through to the closing parenthesis of theELSE
block, substitutes for any%var%
with the PARSE-TIME value ofvar
and THEN executes the result. Consequently,TYPE
will appear unchanged to the logic within the block.You'd need to invoke
delayedexpansion
mode and use!var!
to access the RUN-TIME value ofvar
. This is done with aSETLOCAL ENABLEDELAYEDEXPANSION
statement, usually inserted after the opening@echo off
at the start of the batch (hence turning delayedexpansion and the!var!
facility ON for the entire duration of the batch)Actually, there's no need for an
ELSE
clause as you have it because youGOTO
a label in the true part. This may simplify your code.Finally, there's no
DO/ENDDO
facility in batch - or at least, not in that form. I'll presume that you intend to do the intervening code%dmg%
times. You can achieve this by usingwhere the metavariable
%%z
will be incremented from the first element in the parentheses to the last in steps of the second.%%z
can be any letter, but is one of the very few cases in batch which IS case-sensitive.