C/C++ 105 Loops and conditionals(w/o for loops)

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
2,613
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Mar 7, 2008

going over while loops, if statments and switch cases

Category:

Howto & Style

Tags:

License:

Standard YouTube License

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (ryutenchi)

  • I used switch to control my character in some roguelike game. But I wanted to have a possibility of redefining keys anytime so I did this:

    char Up=0x77 // hex ASCII for 'w'

    char Down=0x73 // hex ASCII for 's'

    switch(PressedKey)

    {  case Up: blabla; case Down: blabla;

    }

    Compiler says Up can't be used after case, the same with Down. Why? :|

  • you can only use constants for cases. So you could either do:

    case 0x77: blah; case 0x73: blah; or

    #define Up 0x77

    #define Down 0x73

    case Up: blah; case Down blah; or

    const char Up = 0x77;

    const char Down = 0x73;...blah

    the reason for this is that each case must be unique and there is no guarantee that they will be if they are not constant

  • Well, that's definitively reasonable. But then, how to make possibility to redefine the keys without recompilation?

  • you can have case 0x77: upArrowCallBack();

    and then set the upArrowCallBack to whatever function you want called when the up key is pressed and then you can have a downArrowCallBack etc. Need me to go over callback functions? as for the cases themselves being set at runtime, in order for the compiler to create the machine code for the program it needs constants there. so those must be constant, but what you do in the actual code for the case can be as dynamic as you like^^

  • Gd videos ! appart from that damm whistling in the backgroud and quiet mic yeah great keep them coming.

  • yeah, I need to get a better mic or get a sound card. thanks for watching despite that!

see all

All Comments (8)

Sign In or Sign Up now to post a comment!
  • GPL DOES NOT mean I can do what I want with it.

    it means I can do what YOU want with it.

    fuck gpl and my tutorials don't have that annoying whistle in the background ;)

  • Seriously, it's to advanced for me by now. As far as I understand, I should do it backwards. Instead of assigning a key to a function, I should prepare case for every possible key and then let user assaign an action to it, is that right?

    After a while I think video on that would be really helpful. I think I am able to solve that riddle myself with help of google, still, I wouldn't mind an example :).

  • I used switch to control my character in some roguelike game. But I wanted to have a possibility of redefining keys anytime so I did this:

    char Up=0x77 // hex ASCII for 'w'

    char Down=0x73 // hex ASCII for 's'

    switch(PressedKey)

    { case Up: blabla; case Down: blabla;

    }

    Compiler says Up can't be used after case, the same with Down. Why? :|

  • I recommend tearing audio apart from video (with virtualdub for instance) and cleaning it with audacity's Noise Removal effect, then joining audio and video back again (virtualdub). That's one way of doing it.

  • fantastic...........thanx.....­......

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more