Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Eleventy

Variables with Undefined Values

This topic is 5528 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way to check if a variable has an undefined value in C++ before using it. For some reason, I sometimes get the main player's position's x, y, or z values ending up being undefined after doing collision detection. I want to know if I can implement a check to correct this so the player doesn't end up being in infinite space . Thanks. EDIT: Fixed anything that was unclear.
My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM [edited by - JoshT172 on May 30, 2003 12:09:58 AM]

Share this post


Link to post
Share on other sites
Advertisement
undefined variables are compile-time errors. Maybe you mean uninitalized?

If that is the case, default values should be provided in constructors and they should never really be magicly reset. You must be doing something else wrong.


-SniperBoB-

Share this post


Link to post
Share on other sites
Sorry, i was a bit unclear, i meant that during the game, sometimes the variable will become undefined (divided by zero) - I can tell this since I have a debug feature that lists all the variables and their values - one of the x, y, or z values of the ship will have -1.#IND as it's value, and the screen will go black (since DirectX can't render an object with an undefined location).


My Project Homepage (Infinity) | E-Mail Me | Message Me on AIM

[edited by - JoshT172 on May 29, 2003 3:33:16 PM]

Share this post


Link to post
Share on other sites
What you have is a bug. Instead of implementing code to check for it and deal with it at runtime, simply fix the bug - make it so your x,y,z values can never be undefined (divided by zero). Something is hammering your variables: get rid of them hammer, don''t put on extra armour.

Share this post


Link to post
Share on other sites
Put a *temporary* check in for the invalid values, and set a breakpoint in it. Then run your app in the debugger, and you''ll hit your breakpoint when your variable gets nuked. Then trace backwards and figure out why. It shouldn''t take long, and it will be worth it, trust me.

Share this post


Link to post
Share on other sites
You probably would have thought of this, but did you make sure you are assigning values to your variables before using them?

"Skepticism.... that great rot of the intellect." - V.H.
Bah, what does HE know?


Albekerky Software

Share this post


Link to post
Share on other sites
quote:
Original post by JoshT172
Is there any way to check if a variable has an undefined value in C++ before using it. For some reason, I sometimes get the main player''s position''s x, y, or z values ending up being undefined after doing collision detection. I want to know if I can implement a check to correct this so the player doesn''t end up being in infinite space . Thanks.



There are functions in the C++ library that return NaN or infinity -- std::numeric_limits::quiet_NaN() and std::numeric_limits::infinity(). You can compare your value to the appropriate one of those.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!