| 1. |
Solve : AOA - Help %Random%? |
|
Answer» As you well know %random% creates a random number between 0 and 32767. If you want the value of %random% to be the same for both formulas, save it and use the saved value in the second formula. Nope, I want them to be different. It all appears to work fine now, so thanks for your help anyway. EDIT: it still has the same problems but it will have to do. as it is roughly fair now anyway.The reason why you are not getting the correct random numbers is because you are not doing the right arithmetic. To get a random number between 1 and 100 you use the modulus operator % thus: set /a var=(%random% %% 100) + 1 Notes: (1) % = modulus (or mod) (N mod M) = the remainder on integer division of N by M (2) To use a percent sign ("%") in a batch file you need to 'escape' it with another one. (To get the effect of % you use %%). Code: [Select]set /a OppDamage=(%random% %% %0Attack%) + 1 set /a Damage=(%random% %% %Attack%) + 1 set /a CHealth=%CHealth%-%OppDamage% set /a OCHealth=%OCHealth%-%Damage% CLOSES the bat file.well im always doeing this like : Code: [Select]%random%%%%var%+1 and it worksI think that 0Attack may be a bad choice for a variable name. Set /a interprets values (including starting with a zero as an octal number. Quote from: Dias de verano on September 14, 2008, 04:00:16 AM I think that 0Attack may be a bad choice for a variable name. Set /a interprets values (including starting with a zero as an octal number. Thanks but it is a capital o not a 0.Quote from: devcom on September 14, 2008, 03:58:42 AM well im always doeing this like : That works brilliantly, thanks to both of you you will receive credits.Quote from: Jacob on September 14, 2008, 04:04:21 AM Quote from: Dias de verano on September 14, 2008, 04:00:16 AMI think that 0Attack may be a bad choice for a variable name. Set /a interprets values (including starting with a zero as an octal number. It is definitely a ZERO. This is the code YOU posted, shown in monospaced font where zero is different from capital 0. Quote from: Dias de verano on September 14, 2008, 04:13:06 AM Quote from: Jacob on September 14, 2008, 04:04:21 AMQuote from: Dias de verano on September 14, 2008, 04:00:16 AMI think that 0Attack may be a bad choice for a variable name. Set /a interprets values (including starting with a zero as an octal number. Thank you, well it's not meant to be, because it stands for opponents attack. Thanks for pointing that out. I have given you credits in the AOA post.Quote from: Jacob on September 14, 2008, 04:14:48 AM well it's not meant to be Those words are written on the gravestones of many many crashed PROGRAMS... Quote from: Dias de verano on September 14, 2008, 04:16:29 AM Quote from: Jacob on September 14, 2008, 04:14:48 AMwell it's not meant to be Lucky I have you. |
|