The Dink Network

This symbol

August 16th 2005, 04:03 PM
pillbug.gif
Drink
Peasant He/Him Chile
Don't drink 
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?
August 16th 2005, 04:22 PM
goblins.gif
igloo15
Peasant He/Him
 
doesn't percent sign mean mod something like
2%5 would equal 1 because 2 goes into 5 twice with a remainder of 1.
August 17th 2005, 07:21 PM
anon.gif
Lurker
Ghost They/Them
 
That is correct. % is modulus.
August 17th 2005, 07:33 PM
goblinm.gif
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.
August 17th 2005, 07:36 PM
goblinm.gif
Obviously I'm missing a "return x;" at the end.
December 6th 2005, 01:36 AM
anon.gif
toa
Ghost They/Them
 
&& 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.
December 6th 2005, 02:06 AM
slimeb.gif
DaVince
Peasant He/Him Netherlands
Olde Time Dinkere 
There are like post dates, man. This was posted 5 months ago.
December 6th 2005, 07:42 AM
duck.gif
Tal
Noble He/Him United States
Super Sexy Tal Pal 
Gee, DaVince and his interesting nature, and someone wanting to rewrite history in this thread? Wow, this board is wild!

*groan groan*
December 6th 2005, 10:50 AM
anon.gif
toa
Ghost They/Them
 
"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.