return value

M

Mike

Hi
when debugging I get the correct AlphaV returned but not when the app
is running.
What could be my fault?
Many thanks
Michael


float FadeIN()
{
....
if (AlphaV < 1.0f)
{
....
{
....
return AlphaV;
}
}
return 0;
}
 
V

Venu Yanamandra

Hi
when debugging I get the correct AlphaV returned but not when the app
is running.
What could be my fault?
Many thanks
Michael

float FadeIN()
{
...
        if (AlphaV < 1.0f)
        {
...
                {
...
                return AlphaV;
                }



}
        return 0;
}- Hide quoted text -

- Show quoted text -

Please 'cout' the 'AlphaV' before you enter the conditional block.
Also, your function does not seem to take any AlphaV input. So, it
looks like some temporary variable or a global one.
I think if you print 'AlphaV' you might get more pointers.
 
F

Fred Zwarts

Mike said:
Hi
when debugging I get the correct AlphaV returned but not when the app
is running.
What could be my fault?
Many thanks
Michael


float FadeIN()
{
...
if (AlphaV < 1.0f)
{
...
{
...
return AlphaV;
}
}
return 0;
}

Please, read the faq about posting code in your question.
Your code is incomplete, so we cannot reproduce your problem.
Your code shows only irrelevant parts of your program,
it does not show the part with the fault.
Try to reduce the program to a small example exhibiting the problem.
Probably, during this reduction, you will find the fault yourself.
So, now we have to guess what your fault could be:
It could be a piece of code with undefined behavior,
such as incorrect sequencing, or array-out-of-bound access.
It could be a wrong compiler option, causing incorrect optimization.
It could be an unsynchronized access to a global variable in a multi-threaded program.
It could be something else.
 
M

Michael

declaration:
float AlphaV = 0.0f;
float FadeIN(float AV);


main function:
FadeIN(AlphaV);
glColor4f(Red, Green, Blue, AlphaV);

fadeinFunction:

float FadeIN(float AlphaV)
{

int start = SDL_GetTicks();

// Only call this when 100 ms have elapsed

if (AlphaV < 1.0f)
{
if( SDL_GetTicks() - start > 10 )
{
// Reassign the time elapsed
start = SDL_GetTicks();

// Increase the alpha value by this much
AlphaV += 0.0005;
}
}
return AlphaV;
}

Still after returning to the main function the AlphaV value is back to
0. Many thanks
Michael
 
A

Alf P. Steinbach /Usenet

* Michael, on 26.08.2010 15:59:
declaration:
float AlphaV = 0.0f;
float FadeIN(float AV);


main function:
FadeIN(AlphaV);
glColor4f(Red, Green, Blue, AlphaV);

fadeinFunction:

float FadeIN(float AlphaV)
{

int start = SDL_GetTicks();

// Only call this when 100 ms have elapsed

if (AlphaV < 1.0f)
{
if( SDL_GetTicks() - start > 10 )
{
// Reassign the time elapsed
start = SDL_GetTicks();

// Increase the alpha value by this much
AlphaV += 0.0005;
}
}
return AlphaV;
}

Still after returning to the main function the AlphaV value is back to
0. Many thanks

There are two reasons why nothing happens to AlphaV. First, in your main
function you do not assign to AlphaV. This means that it's not changing: the
call to FadeIN just passes its value to the function and nothing else.

Second, in the FadeIN function you initialize 'start' as SDL_GetTicks(). And you
pretty immediately check whether SDL_GetTicks() has progressed to a value 10
larger. Most probably it hasn't, and so in FadeIn nothing is done.

By the way, please just post real code, not descriptions. For example, it's
impossible to say whether your "declaration:" is global or local in 'main' or
wherever. And that does have some bearing on the question you're asking...


Cheers & hth.,

- Alf
 
V

Victor Bazarov

declaration:
float AlphaV = 0.0f;
float FadeIN(float AV);


main function:
FadeIN(AlphaV);
glColor4f(Red, Green, Blue, AlphaV);

fadeinFunction:

float FadeIN(float AlphaV)
{

int start = SDL_GetTicks();

// Only call this when 100 ms have elapsed

if (AlphaV < 1.0f)
{
if( SDL_GetTicks() - start > 10 )
{
// Reassign the time elapsed
start = SDL_GetTicks();

// Increase the alpha value by this much
AlphaV += 0.0005;
}
}
return AlphaV;
}

Still after returning to the main function the AlphaV value is back to
0. Many thanks
Michael

Do you understand what is written in the FAQ 5.8? If you do, and still
post the code the way you posted here, then methinks you don't really
care if you get any help from us, which is unlikely. If you don't
understand the recommendations of FAQ 5.8, then what is it that you
don't understand? Let's discuss it, it will lead to the improved FAQ
list and clearer understanding on your part.

V
 
M

Mike

Do you understand what is written in the FAQ 5.8?  If you do, and still
What are u talking about?



Declarations are at the beginning, so global as not within a function?
Therefore I don't understand why AlphaV gets resetted to 0.
Thanks


float AlphaV = 0.0f;
float FadeIN(float AV);
 
T

tni

declaration:
float AlphaV = 0.0f;
float FadeIN(float AV);


main function:
FadeIN(AlphaV);
glColor4f(Red, Green, Blue, AlphaV);

fadeinFunction:

float FadeIN(float AlphaV)
{

int start = SDL_GetTicks();

// Only call this when 100 ms have elapsed

if (AlphaV < 1.0f)
{
if( SDL_GetTicks() - start > 10 )
{
// Reassign the time elapsed
start = SDL_GetTicks();

// Increase the alpha value by this much
AlphaV += 0.0005;
}
}
return AlphaV;
}

Still after returning to the main function the AlphaV value is back to
0. Many thanks
Michael

Your AlphaV parameter in FadeIN() hides the AlphaV in main().
 
G

Gennaro Prota

* Michael, on 26.08.2010 15:59:

There are two reasons why nothing happens to AlphaV. First, in your main
function you do not assign to AlphaV. This means that it's not changing: the
call to FadeIN just passes its value to the function and nothing else.

I'm under the impression that he thinks that the function is
going to modify the global AlphaV, as if its parameter was a
reference. (In his first post, he also says that the value "is
correct in the debugger", or something like that, probably
because he is looking at the parameter, which alas has the same
name.)
 
M

Mike

Your AlphaV parameter in FadeIN() hides the AlphaV in main().

hmm so how should I declare AlphaV then?
Thanks

float AlphaV = 0.0f;
float FadeIN(float AV);


PS: FadeIN() is not called in main but called from:
int DrawGLScene(float left, float top, float right, float bottom, int
texNr)
{
 
M

mingze zhang

hmm so how should I declare AlphaV then?
Thanks

float AlphaV = 0.0f;
float FadeIN(float AV);

PS: FadeIN() is not called in main but called from:
int DrawGLScene(float left, float top, float right, float bottom, int
texNr)
{


It seems that you are trying to work on hard and complicated programs
without even knowing some of the basic features of C programming
language (not even C++).

You can directly use a global variable in your functions. So your
FadeIn function shall be something like,

float FadeIN()
{
int start = SDL_GetTicks();
// Only call this when 100 ms have elapsed
if (AlphaV < 1.0f)
{
if( SDL_GetTicks() - start > 10 )
{
// Reassign the time elapsed
start = SDL_GetTicks();
// Increase the alpha value by this much
AlphaV += 0.0005;
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top