variable shadows a previous declaration ?

   3431   2   0
User Avatar
Member
1007 posts
Joined: April 2017
Offline
Hi!

I'm using vex to figure out the width of a rectangle shape and I get an error but I don't get how to fix it. I was trying to initialize the “axis” variable so it would be 0. Right after that, I use an “if” statement that could change the value of “axis” to 1:

// find bbox dimensions
vector max = getbbox_max(0);
vector min = getbbox_min(0);

vector dif = max-min;

// find longest axis length
float biggest = max(dif.x, dif.y, dif.z);

// find what axis is width (X or Z). If 0 -> Z. If 1 -> X.
float axis = 0;

if(dif.z == biggest){
float axis = 1; //error: Declaration of variable ‘axis’ shadows a previous declaration at line 11.
}

How should I change the code?

Thanks.

-Olivier
User Avatar
Member
7762 posts
Joined: Sept. 2011
Offline
after axis is declared you don't need to declare it again:

float axis = 0;

if (cond){
    axis = 1;
}
User Avatar
Member
1007 posts
Joined: April 2017
Offline
Ahhhhh!!! DOOOHHH!!

Thanks!

-Olivier
  • Quick Links