@faaip wrote:
Hey all! I have an issue that's been bugging me all day. The code is quite verbose, so I'll try explain using just a snippet. Basically I have a class called Location where the update() and draw() methods are receiving a vector of user coordinates as input. In update() it's for calculating number of users close to each location.
void Location::update(vector <userCircle>& users){ noOfUsersClose = 0; // reset number of close users int closestDist = 40000; // basically just a high value for(userCircle u : users){ if(ofDist(coordinates.x,coordinates.y,u.coordinates.x,u.coordinates.y) < distanceThreshold) { noOfUsersClose++; } if(ofDist(coordinates.x,coordinates.y,u.coordinates.x,u.coordinates.y) < closestDist) { closestDist = ofDist(coordinates.x,coordinates.y,u.coordinates.x,u.coordinates.y); } } cout << ofToString(noOfUsersClose) + "\n"; }
When I print the noOfUsersClose here, I get the desired result. If no users are close it prints 0.
In the draw()-method, however, I print noOfUsersClose as the first thing and no these values change.void Location::draw(vector <userCircle>& users) { cout << ofToString(noOfUsersClose) + "\n";
It's a global variable assigned in the header-file. Am I somehow assigning the value of the integer wrong?
Hope to hear from you!
Fred
Posts: 3
Participants: 2