Page 1 of 1

A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 2:32 am
by happyjustbecause
Hello again everyone. One of the powers used by the player of my game is available to use after a variable reaches a certain number. Once this variable hits 1000 an icon's transparency turns from .9 to 0. I want to make it so that the transparency of the icon goes down while the AvailableHologramTimer varaible goes up. How can I do this? Rather than doing something like this:

Code: Select all
if(AvailableHologramTimer==125)
{
    transp=.8;
}
if(AvailableHologramTimer==250)
{
    transp=.7;
}


Is there some kind of formula that I can have so that the transparency goes down when the variable goes up.

Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 3:06 am
by skydereign
happyjustbecause wrote:Is there some kind of formula that I can have so that the transparency goes down when the variable goes up.

Subtracting the number works just like that.
Code: Select all
transp = (1000.0-AvailableHologramTimer)/1000.0;

Of course you'll need to set the min max to fit your use case.

Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 3:21 am
by happyjustbecause
Well I just tried that code and it seems to be working when I added this:

Code: Select all
switch(AvailableHologramTimer)
{
    case 0:
    transp = (1000.0-AvailableHologramTimer)/1000.0;
    break;

    case 1:
    transp=0;
    break;
}


I added the switch just to prevent any problems with the hologram being available and the transparency not being 0. I only noticed this because I have a key down event which makes all the powers available without setting the timer to 1000.

Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 3:25 am
by skydereign
You sure that is what you want? That code is the same thing as doing this.
Code: Select all
switch(AvailableHologramTimer)
{
    case 0:
    transp = 1;
    break;

    case 1:
    transp=0;
    break;
}

Which is the same as just doing this.
Code: Select all
transp = AvailableHologramTimer==0;

Which I'm pretty sure isn't what you wanted.

Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 3:29 am
by happyjustbecause
Umm I don't really know what:

Code: Select all
transp = AvailableHologramTimer==0;


means. But it seems the code I just added is working, the hologram's icon goes down in transparency as the power is getting closer for availability.

Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 3:33 am
by skydereign
Ok, then you must be using different code (switched a variable name). Because the code you said you are using is exactly like I mentioned in my last post. The switch statement only triggers code if the variable is 0 or 1. In the case of 0, the variable is 0, so that transp = ... bit is the same thing as saying transp = 1000/1000 which is 1.

happyjustbecause wrote:Umm I don't really know what:

Code: Select all
transp = AvailableHologramTimer==0;


means. But it seems the code I just added is working, the hologram's icon goes down in transparency as the power is getting closer for availability.

This is that boolean math I mentioned to you a while ago. var==0 returns a 1 if the statement is true, and a 0 if it is false. And that happens to be exactly what the code you posted does.

Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 8:49 pm
by happyjustbecause
Hmm... Well I thought the code meant that essentially 1 unit of transparency equals 1000 of the AvailableHolgramTimer. I didn't really look at the actual code to think this, just what I saw the game do with it. Here's a video I just made showing the code and the gameplay doing what apparently shouldn't be happening.


Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 8:59 pm
by skydereign
Yeah, as I thought. The code in game is different than the one you posted. This is what you had.
Code: Select all
switch(AvailableHologramTimer)
{
    case 0:
    transp = (1000.0-AvailableHologramTimer)/1000.0;
    break;

    case 1:
    transp=0;
    break;
}

And this is what you have in game.
Code: Select all
switch(AvailableHologram)
{
    case 0:
    transp = (1000.0-AvailableHologramTimer)/1000.0;
    break;

    case 1:
    transp=0;
    break;
}

They are very different, and that explains why it works properly.

Re: A Help With Transparency/if statements

PostPosted: Tue Dec 11, 2012 9:28 pm
by happyjustbecause
Ohhh... I thought there would be something different, I was paying attention to the transp = (1000.0...)

sorry about that. Thank you for the help again!