This symbol
In this line:
if (hurt_thing(i, (spr[h].strength / 2) + ((rand() % ((spr[h].strength+1) / 2))+1), 0) > 0)
...What does that symbol "%"?
It is really complicated to read that line, so I have simpified it. Here:
----
StrenghtDiv2 = spr[h].strength / 2;
Random = rand();
StrenghtPlus1Div2 = (spr[h].strength + 1) /2;
if (hurt_thing(i, StrengthDiv2 + ((Random % StrengthPlus1Div2) +1), 0) > 0)
----
What operation produces (Random % StrengthPlus1Div2)?
Also, please correct me on this if it is incorrect:
/ means division
// means comment until end of line
/* means the start of a commented block
*/ means end of commented block.
(A || B) means OR, like (10 or 01) = 11
(A && B) means AND, like 11 and 00 = 00
(!A) means NOT A
The strange thing is that I saw (A & B) and (A | B), with only single symbol each.
So, in that way, these symbols means something different?
if (hurt_thing(i, (spr[h].strength / 2) + ((rand() % ((spr[h].strength+1) / 2))+1), 0) > 0)
...What does that symbol "%"?
It is really complicated to read that line, so I have simpified it. Here:
----
StrenghtDiv2 = spr[h].strength / 2;
Random = rand();
StrenghtPlus1Div2 = (spr[h].strength + 1) /2;
if (hurt_thing(i, StrengthDiv2 + ((Random % StrengthPlus1Div2) +1), 0) > 0)
----
What operation produces (Random % StrengthPlus1Div2)?
Also, please correct me on this if it is incorrect:
/ means division
// means comment until end of line
/* means the start of a commented block
*/ means end of commented block.
(A || B) means OR, like (10 or 01) = 11
(A && B) means AND, like 11 and 00 = 00
(!A) means NOT A
The strange thing is that I saw (A & B) and (A | B), with only single symbol each.
So, in that way, these symbols means something different?
doesn't percent sign mean mod something like
2%5 would equal 1 because 2 goes into 5 twice with a remainder of 1.
2%5 would equal 1 because 2 goes into 5 twice with a remainder of 1.
I once wrote (and constantly reused) a C++ function like the following:
int amodb(int a, int b)
{
int x = a / b;
x = bx;
a = a - x;
}
I felt really stupid when I first learned what % meant.
int amodb(int a, int b)
{
int x = a / b;
x = bx;
a = a - x;
}
I felt really stupid when I first learned what % meant.
December 6th 2005, 01:36 AM

toa


&& and || are logical operators, & and | are bitwise. (There are many articles on the net which explain the difference better than I can.)
% is modulus. It's most often used as a limit-check since the result of C=A%B will never be greater than or equal to B (C is always less than B).
So what the expression is doing is:
half-strength + (random amount less than half-strength) + 1
This will cause damage to sprite i (the first argument) in the range strength/2 to strength.
And the + 1 at the end just ensures that at least 1 point of damage is done.
% is modulus. It's most often used as a limit-check since the result of C=A%B will never be greater than or equal to B (C is always less than B).
So what the expression is doing is:
half-strength + (random amount less than half-strength) + 1
This will cause damage to sprite i (the first argument) in the range strength/2 to strength.
And the + 1 at the end just ensures that at least 1 point of damage is done.
There are like post dates, man. This was posted 5 months ago.
Gee, DaVince and his interesting nature, and someone wanting to rewrite history in this thread? Wow, this board is wild!
*groan groan*
*groan groan*
December 6th 2005, 10:50 AM

toa


"There are like post dates, man. This was posted 5 months ago."
I'm the guy who didn't know this site had a message board until redink explicitly told me about it.
Thanks for the heads up on the dates. I'll try to find out where they're displayed.
I'm the guy who didn't know this site had a message board until redink explicitly told me about it.
Thanks for the heads up on the dates. I'll try to find out where they're displayed.