Jump to content

entitydistance vars


cassius
 Share

Recommended Posts

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..

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

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.

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

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.

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...