Aller au contenu

Photo

Scripting Finesse: making sure a location is valid before returning it.


  • Veuillez vous connecter pour répondre
3 réponses à ce sujet

#1
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
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?

#2
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 598 messages
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

Modifié par Kaldor Silverwand, 19 mai 2011 - 02:33 .


#3
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
I'm sure the function CalcSafeLocation() can be useful in there too.

#4
M. Rieder

M. Rieder
  • Members
  • 2 530 messages
@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.