1.

Solve : AOA - Help %Random%?

Answer»

As you well know %random% creates a random number between 0 and 32767.
In my formulas for combat. I think when %random% is set automatically it uses the new %random% in the next formula.

So:
Code: [SELECT]set /a OppDamage=(%random%*%OAttack%/32767)-10
set /a Damage=(%random%*%Attack%/32767)-10

set /a CHealth=%CHealth%-%OppDamage%
set /a OCHealth=%OCHealth%-%Damage%


EDIT: one formula comes back normally and one around the 20's

this switches dependent on which formula is first#

Each time I run the bat again the %Damage% or %OppDamage% is almost always the same DEPENDING on which formula is worked out before the other one.

This will better explain it:


EDIT:
I'm not sure how, but it works almost perfectly now, and works good enough for me at this precise moment, if you know why PLEASE do not hesitate to post as a permanent fix will be greatly appreciated.Not sure I understand. %random% generates a new random number each time it is encountered in the code (exception is within a for loop when special consideration must be made).

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.

You also have the values of %OAttack% and %Attack% to consider when you view your results.

The little piece of doggerel will show random number generation over a wide range:

Code: [Select]@echo off
for /l %%v in (1,1,10) do (
call echo %%random%%
)

Quote from: Sidewinder on September 13, 2008, 11:42:18 AM

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 :

Code: [Select]%random%%%%var%+1
and it works

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 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.

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 AM
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.

It is definitely a ZERO. This is the code YOU posted, shown in monotype font where zero is different from capital 0.



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 AM
well it's not meant to be

Those words are written on the gravestones of many many crashed programs...

Lucky I have you.


Discussion

No Comment Found