I made a quick function to return a random location around a central point. Before I return the location in the function, I use a while loop to make sure it is valid.
Code to calculae lLocation;
while(!GetIsLocationValid(lLocation))
{
Code to re-calculate lLocation;
}
return lLocation;
Is this a safe and efficient way to do this or am I setting myself up for trouble?
Scripting Finesse: making sure a location is valid before returning it.
Débuté par
M. Rieder
, mai 19 2011 12:45
#1
Posté 19 mai 2011 - 12:45
#2
Posté 19 mai 2011 - 02:32
I would restructure it so that you do not need to do the calculate in two places, like so:
location lLocation;
int done = FALSE;
while (!done)
{
// code to calculate random lLocation goes here
done = GetIsLocationValid(lLocation); // indicate done if location is valid
}
Regards
location lLocation;
int done = FALSE;
while (!done)
{
// code to calculate random lLocation goes here
done = GetIsLocationValid(lLocation); // indicate done if location is valid
}
Regards
Modifié par Kaldor Silverwand, 19 mai 2011 - 02:33 .
#3
Posté 19 mai 2011 - 02:53
I'm sure the function CalcSafeLocation() can be useful in there too.
#4
Posté 19 mai 2011 - 12:48
@Kaldor
Thanks, that is better.
@KM
I wanted to use that function, but it requires an object to calculate the safe location from and I don't have an object to calculate from. I tried to find a function that calculated from a location, but none really fit my needs and I realized that in the time I was using to find one, I could just make one.
Thanks, that is better.
@KM
I wanted to use that function, but it requires an object to calculate the safe location from and I don't have an object to calculate from. I tried to find a function that calculated from a location, but none really fit my needs and I realized that in the time I was using to find one, I could just make one.





Retour en haut






