Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-14-2007, 03:20 PM   #1 (permalink)
Mordacai058
Recruit
 
Join Date: Mar 2007
Posts: 3
Mordacai058 is on a distinguished road
Ternary Operator Question

I need help with the ternary operator...
I have a program with a bitmap array and I want one to show up normally and one if I press control(I know that the control key is being recognized correctly). Here is what I put, 0 is the normal, 1 is the one for when the key is pressed

Code:
  g_pSaucer[((booster)?1:0)]->Draw(hDC, g_iSaucerX, g_iSaucerY, TRUE);
  booster = 0;
And draw works right, because the normal or zero always shows up... here is the code i'm trying to use to get the bitmap to change.
Code:
  if (GetAsyncKeyState(VK_CONTROL) < 0)
{  
  booster = 1;
  g_iSpeedY = g_iSpeedY - 2;
}
Mordacai058 is offline   Reply With Quote
Old 03-14-2007, 04:23 PM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
and what is the question?
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-14-2007, 04:47 PM   #3 (permalink)
Mordacai058
Recruit
 
Join Date: Mar 2007
Posts: 3
Mordacai058 is on a distinguished road
Sorry.. i was stupid. I had added joystick support where if the joystick was on and the 1st button was pressed it worked... but i don't have a joystick so even though i set the variable to true it didn't work because the joystick part was setting it to false. So that's why it didn't work... to make it work with both i think i'll try an or operator...
Mordacai058 is offline   Reply With Quote
Old 03-16-2007, 04:18 PM   #4 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
what does a joystick have to do with the control key or the ternary operator?

You definitely need to think or i shall report this useless topic.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-17-2007, 10:22 AM   #5 (permalink)
Mordacai058
Recruit
 
Join Date: Mar 2007
Posts: 3
Mordacai058 is on a distinguished road
Useless?

One, if your "regular contributers" don't even read, or are just stupid, I don't think I want to be on this forum anyway. Secondly, the joystick and control key are obviously of importance considering that was the reason that the program was not working correctly, as I explained in my previous post. Why this is is becuase the control key was supposed to set g_bSaucerFlame to 1 or true, like the posted code says. However, I had added joystick support and it set g_bSaucerFlame to the state of the joystick(Connected or not) & the state of the button(Pressed or not), Therefore since I didn't have a joystick it would always set g_bSaucerFlame back to 0 or false before it got to the main program. So I had to use the ||, or operator to get it to work with two variables, one for if the control key was pressed, one for if the joystick button 1 was pressed. And now it works. This code now causes the UFO to have flames shooting out of the bottom when the control or joystick button 1 is pressed as well as causing a boost upwards.

So thanks for your useless threats and remove it, however I think it's a good learning oppurtunity so that newer programmers(like me) will make sure to check such things.
Mordacai058 is offline   Reply With Quote
Old 03-17-2007, 11:33 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
let's not forget we're at 'code newbie', and like people feeling comfortable they can ask/post anything programming related in a positive environment, even if they don't exactly know how to put it. we rarely moderate content unless it is spam.
__________________
Mike
sde is offline   Reply With Quote
Old 03-17-2007, 12:10 PM   #7 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 734
DJMaze is on a distinguished road
@Mordacai058

well, thank you for explaining what you wanted to achieve and that it works now.

I was flaming because your first post was about the ternary operator and VK_CONTROL and there was nothing about joystick support or anything else.
Also the code you provided works perfectly with ternary.

So how would i have been able to guess what you wanted to achieve?

@SDE

'code newbie' == 'forum newbie' ????
I like to help but a topic without a question and missing the actual needed data to analyze is impossible
It's like "my car won't start." and then forgot to tell i've lost the key
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-17-2007, 01:05 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,529
sde is on a distinguished road
yeah, i understood where you were coming from djm but we still like to keep it flameless around here. (i can think of a couple rare exceptions ) your help is always appreciated though.
__________________
Mike
sde is offline   Reply With Quote
Old 03-17-2007, 02:52 PM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
I'll support DjM here, at first I didnt see any real question, as the ternary operator has nothing todo with the solution. When it was fased out with "Oh, I just got it working" I kinda lost interrest.

But as allways, try to keep the flames here at an acceptable level, theres no reason for any namecalling, btw Mordacai, as for "Regular contributers" I wouldn't point fingers at DjM as he is one of the smart people around..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ ternary operator... sde Standard C, C++ 4 06-15-2002 01:22 PM


All times are GMT -8. The time now is 01:53 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting