Quick noob question heh

if i have
int iStalkRange = 40;

and then i do like

int plusAttacklRange = iStalkRange + 1 || iStalkRange + 2;

means plusAttackRange can be 41 or 42?

or should it be like

int plusAttacklRange = iStalkRange + 1 || plusAttacklRange = iStalkRange + 2;


ok now i know im wrong, which would be the code to make plusAttackRange be 41 or 42?
Last edited on
means plusAttackRange can be 41 or 42?

God, no. || is an operator that takes two boolean operands and returns true if one of them is true. Non-zero integer numbers are converted to true in a boolean context, so you have true || true, which is true. true can be converted to an integer (1), so plusAttacklRange will be 1.

What are you even trying to accomplish? Generating a random number within a range?
Last edited on
God, no. || is an operator that takes two boolean operands and returns true if one of them is true. Non-zero integer numbers are converted to true in a boolean context, so you have true || true, which is true. true can be converted to an integer (1), so plusAttacklRange will be 1.

What are you even trying to accomplish? Generating a random number within a range?


yea exactly, which would be the correct code?
Last edited on
int plusAttacklRange = iStalkRange + 1 || iStalkRange + 2;
|| is logical OR. It returns true if one of the sides are true. You have not used boolean (true/false) values but any non-zero value will be treated as true, zero treated as false. That means iStalkRange + 1 || iStalkRange + 2 is the same as true || true, which is true. true converted to an integer is 1 so plusAttacklRange will get the value 1.
Last edited on
|| is logical OR. It returns true if one of the sides are true. You have not used boolean (true/false) values but any non-zero value will be treated as true, zero treated as false. That means iStalkRange + 1 || iStalkRange + 2 will be handled as true || true which is true. true converted to an integer is 1 so plusAttacklRange will get the value 1.


so how could i accomplish plusAttackRange be 41 or 42?
Last edited on
By using rand(), for example:
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/


oh sorry i miss read that, what i realy want to do is to make plusAttackRange stand for different values like that when i use it for example here:

if (iCharX() == (plusAttackRange) - iMobX())

what i want to do is that plusAttackRange can stand for the values i want, for examle 41 or 42
You make a variable "stand for something" by assigning a value to it.
Describe properly what you're trying to do.
okay so this is my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void Stalker()
{
	MShWnd = FindProcessWindow();
	while(!bStalker)
  {
	  Sleep(10);

	  if (iCharX() < (iStalkRange) + iMobX())
	{	
		if (bWalk == true)
		{

		Sleep(100);
		keybd_event(VK_LEFT,0, KEYEVENTF_KEYUP,0); // Left Release
		Sleep(50);
		keybd_event(VK_RIGHT,0,0 , 0);//Press Right
		}
	}

	  else if (iCharX() > (iStalkRange) - iMobX())
	{
		if (bWalk == true)
		{
		Sleep(100);
		keybd_event(VK_RIGHT,0, KEYEVENTF_KEYUP,0); // Right Release
		Sleep(50);
		keybd_event(VK_LEFT,0,0 , 0);//Press Left
		}
   }

	}

}


what this does is basicly CharX follows MobX by moving right or left (it is a game)

and what im trying to do here its that when CharX gets to MobX coords -iStalkRange or + iStalkRange (depends wether you are going right or left)
press a key.

but my problem is that if i use

if (iCharX() == (iStalkRange) - iMobX())
{
if (bWalk == true)
{
//key press
}

my charX changes really fast so it is unlikely that it will ever be == (iStalkRange) - iMobX()

so what im trying to do here is make plusAttacklRange stand for iStalkRange or iStalkRange+1 or iStalkRange+2(like +40 but i only did +1, +2 to set example)

so then if i write
if (iCharX() == (plusAttacklRange ) - iMobX())
{
if (bWalk == true)
{
//key press
}

it has more chances for my Charx of being == (plusAttacklRange ) - iMobX()

and yeah thats my problem here
Last edited on
Ah, alright. That's just simple subtraction:

1
2
3
4
const int stalkRange=2;
if (charX>mobX && charX-mobX<=stalkRange) //character is on the right and within range
if (charX<mobX && mobX-charX<=stalkRange) //character is on the left and within range
if (abs(charX-mobX)<=stalkRange) //character is on either side, but within range 
Topic archived. No new replies allowed.