About Store Forum Documentation Contact



Post Reply 
C++ question (probably a real basic one)
Author Message
dicedealer Offline
Member

Post: #1
C++ question (probably a real basic one)
Hey everybody,

Well I been studying C++ like crazy... and I came across something that i just dont get and im having trouble finding an answer to it... I wonder if any of you could help out a fledgling noob programmer wannabe =-)

The question is:

When you have a function that is not of type void.. you must have a return statement at the end of the function and that return statement must return a value. What i dont understand is... what is the point of a function returning a value? Could someone give me an example of how a function returning a value could have a practical use in game programming? Thank you all in advance very much for helping me to understand this.
04-17-2011 07:49 AM
Find all posts by this user Quote this message in a reply
siwykon Offline
Member

Post: #2
RE: C++ question (probably a real basic one)
I think that you want something like this:

Str GetItemMeshName(Item itm)
{
return itm.mesh.name(); //Return Item mesh name to Str
}

Next you can use it, for example:

D.text(0,0,S+GetItemMeshName(Items[0]));
(This post was last modified: 04-17-2011 08:25 AM by siwykon.)
04-17-2011 08:16 AM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #3
RE: C++ question (probably a real basic one)
Lets say you have a text on the bottom left corner of your screen: D.text(-1.2,-1,"sdfsdsdf");

..but you want to make it more cool looking, more exciting. You feel like you want that text to move across the screen slowly, then fast, then out of site.

Since the first parameter of D.text is the x location of the text, and since it's a constant, it won't do what you want it to do.

To tackle this is to make a simple function. Lets call this function calcx. Since the first parameter of D.text takes in a Flt, this function would also have to return the same type, type Flt. So, lets declare it and also a variable for x.

Code:
Flt x = -1.3; //initial starting position of x
Flt calcx()
{
    if(pressed>3)//pause for 3 seconds, then animate.
    {        
        x=x*-x);//changes x position
    }
    
    if(x>=1.3)
    {
        stopdrawing();//x posistion is offscreen. stop drawing
    }
    return x;
}

Okay,the function is done, time to use it: D.text(calcx(),-1,"sdfsdsdf");
Now it moves, cool.
04-17-2011 08:43 AM
Find all posts by this user Quote this message in a reply
Post Reply