Reputation: 437
I am writing a program in batch. It has to take a variable which is a number and add or subtract from that variable to get another number.
I currently have:
set /A str="%RANDOM% %% 6"+1+"%RANDOM% %% 6"+1+"%RANDOM% %% 6"+3
set /A dex="%RANDOM% %% 6"+1+"%RANDOM% %% 6"+1+"%RANDOM% %% 6"+3
set /A con="%RANDOM% %% 6"+1+"%RANDOM% %% 6"+1+"%RANDOM% %% 6"+3
set /A int="%RANDOM% %% 6"+1+"%RANDOM% %% 6"+1+"%RANDOM% %% 6"+3
set /A wis="%RANDOM% %% 6"+1+"%RANDOM% %% 6"+1+"%RANDOM% %% 6"+3
set /A cha="%RANDOM% %% 6"+1+"%RANDOM% %% 6"+1+"%RANDOM% %% 6"+3
set /a Data11="%str% %% 1"+2
set /a Data12=%dex%
set /a Data13="%con% %% 1"+2
set /a Data14="%int% %% 1"-2
set /a Data15=%wis%
set /a Data16=%cha%
Unfortunately it is currently setting the Data11, 13, and 14 to just the +2 or -2.
I want it to work this way so I can have many different sets of alterations to preform on the str, dex, ectra variables which in turn depend on user input and choice.
How can I get it to work as intended?
Upvotes: 0
Views: 60
Reputation: 41234
You don't need quotes for most arithmetic or percent signs on normal variables
- and I removed the %% 1
for this example.
set /A str=%RANDOM% %% 6+1+%RANDOM% %% 6+1+%RANDOM% %% 6+3
set /A dex=%RANDOM% %% 6+1+%RANDOM% %% 6+1+%RANDOM% %% 6+3
set /A con=%RANDOM% %% 6+1+%RANDOM% %% 6+1+%RANDOM% %% 6+3
set /A int=%RANDOM% %% 6+1+%RANDOM% %% 6+1+%RANDOM% %% 6+3
set /A wis=%RANDOM% %% 6+1+%RANDOM% %% 6+1+%RANDOM% %% 6+3
set /A cha=%RANDOM% %% 6+1+%RANDOM% %% 6+1+%RANDOM% %% 6+3
set /a Data11=str + 2
set /a Data12=dex
set /a Data13=con + 2
set /a Data14=int - 2
set /a Data15=wis
set /a Data16=cha
set data
pause
Upvotes: 1
Reputation: 1076
Note that the following are also valid:
SET/A Data11="str %% 2 + 2"
SET/A "Data11=str %% 2 + 2"
SET/A Data12=dex
SET/A temp=dex+1
More information and examples:
Upvotes: 0