cassius Posted September 14, 2012 Share Posted September 14, 2012 Heres another c noob question. In c or c++ it seems you have to put a variable in front of EntityDistance, unlike BMax where " if Entitydistance(a,B) will do my question is can I use the same variable ( "dist" for example ) more than once without causing confusion? I use EntityDistance many times in my game.. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Pixel Perfect Posted September 14, 2012 Share Posted September 14, 2012 In C you can do either really depending on what it is you are wanting to do: For instance, if you want to store the value for some later point then you can assign a variable the value returned from EntityDistance as follows: float dist = EntityDistance(Entity1,Entity2); But if you just wanted to test the value with an if statement for example then there is no need for the variable, the return value is simply used in the comparision: if(EntityDistance(Entity1,Entity2) <= 2.0) { ... do something } With regard to re-use of the same variable, then yes, this is possible depending on the scope (life) of the variable, but not always desirable. It is generally better practice to scope your variables locally. Quote Intel Core i5 2.66 GHz, Asus P7P55D, 8Gb DDR3 RAM, GTX460 1Gb DDR5, Windows 7 (x64), LE Editor, GMax, 3DWS, UU3D Pro, Texture Maker Pro, Shader Map Pro. Development language: C/C++ Link to comment Share on other sites More sharing options...
cassius Posted September 14, 2012 Author Share Posted September 14, 2012 Ah good. I tried the second one you mentioned but got an error message. Must have been a syntax error. I am finding some of the error messages hard to figure in codeblocks. Thanks again. Quote amd quad core 4 ghz / geforce 660 ti 2gb / win 10 Blender,gimp,silo2,ac3d,,audacity,Hexagon / using c++ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.