Hello, in this code below I have divided the code into two Sections, so I can make things clear. In First section, I declared the variables and initialized them. In Second section, I am trying to write if statement in for loop. As you can see I want to generate random numbers from 0.0 to 1.0 (float V = rand->uniformReal(0.0,1.0);) and whenever this random number is smaller than 0.5 which is attackLevel, I get 1 in the last variable in location and else I get 0. Please Notice that Location with capital L is another class and this code is from the main.cpp file. Location class has location object with variables (float x, float y, float z). Basically I want the variable z to be 1 or 0 depending on the if statement.
when I run the program, I get this error message from the compiler "‘location’ was not declared in this scope"
if (V < attackLevel)
Location location(rand->uniformReal(0.0, (locationFactor * 2.4)),0,1);
//is the same as
if (V < attackLevel){
Location location(rand->uniformReal(0.0, (locationFactor * 2.4)),0,1);
} //end of scope, 'location' dies here
that's why you can't access 'location' outside.
what you may do
1 2 3 4 5 6
double z;
if (V < attackLevel)
z = 1;
else
z = 0;
Location location(rand->uniformReal(0.0, (locationFactor * 2.4)),0,z);