Latest Diablo 3 News
DiabloWiki Updates
Support the site! Become a Diablo: IncGamers PAL - Remove ads and more!

Programming help

Discussion in 'Off-Topic' started by Dondrei, Nov 14, 2006.

  1. Dondrei

    Dondrei IncGamers Member

    Joined:
    Aug 1, 2005
    Messages:
    36,855
    Likes Received:
    30
    Trophy Points:
    467
    Programming help

    Okay, I'm stumped. I'm probably doing something really stupid again, but here goes:

    These are the important parts of my code. This is inside a main loop, so the idea is to switch between states in every frame (well, I also built in a delay to do it every five frames, but you get the picture). For some reason the sprite suddenly stayed in state 0.

    I found a number of other ways to do this, but I'd still like to know what was wrong with what I had.
     
  2. AJK

    AJK IncGamers Member

    Joined:
    Feb 18, 2006
    Messages:
    2,447
    Likes Received:
    3
    Trophy Points:
    166
    Try
    Code:
    spritestate = 0;
    
    if (spritestate [highlight]==[/highlight] 0) {spritestate = 1;} else {spritestate = 0;}
     
  3. Dondrei

    Dondrei IncGamers Member

    Joined:
    Aug 1, 2005
    Messages:
    36,855
    Likes Received:
    30
    Trophy Points:
    467
    Oh, for Christ's sake...
     
  4. DPH

    DPH IncGamers Member

    Joined:
    Mar 21, 2006
    Messages:
    1,331
    Likes Received:
    0
    Trophy Points:
    255
    That brought a smile to my face. Thanks
     
  5. myleftfoot

    myleftfoot IncGamers Member

    Joined:
    Oct 8, 2004
    Messages:
    1,931
    Likes Received:
    0
    Trophy Points:
    165


    You've got a long way to go Don. Best of luck.



     
  6. SaroDarksbane

    SaroDarksbane IncGamers Site Pal

    Joined:
    Jul 3, 2003
    Messages:
    8,563
    Likes Received:
    8
    Trophy Points:
    467
    Haha, nice one Donny.

    If you only have 2 states, you might also try a Boolean.
    Code:
    bool spritestate = 0;
    spritestate = !spritestate;
    So it'll set the state to the opposite of whatever it was before, and you don't have to use a clunky If/Else structure.
     
  7. DurfBarian

    DurfBarian IncGamers Member

    Joined:
    Jun 22, 2003
    Messages:
    9,708
    Likes Received:
    18
    Trophy Points:
    467
    10 ?"DONDREI IS TEH DUM"
    20 GOTO 10

    I thought you already had a thread for your failures. ;-)
     
  8. bladesyz

    bladesyz IncGamers Member

    Joined:
    Jul 8, 2005
    Messages:
    2,027
    Likes Received:
    0
    Trophy Points:
    255
    lol, I can't believe I didn't pick that up at first. It's a classic!
     
  9. SaroDarksbane

    SaroDarksbane IncGamers Site Pal

    Joined:
    Jul 3, 2003
    Messages:
    8,563
    Likes Received:
    8
    Trophy Points:
    467
    This one is even better, and it's fun as a prank too!

    Can you spot the error?
    Code:
    for(int x = 0; x < y; x++); {
       // Do a bunch of stuff here
    }
    They'll spend hours trying to figure out why their code isn't working.



     
  10. myleftfoot

    myleftfoot IncGamers Member

    Joined:
    Oct 8, 2004
    Messages:
    1,931
    Likes Received:
    0
    Trophy Points:
    165
    These things can be shockingly time wasting :smiley:



     
  11. bladesyz

    bladesyz IncGamers Member

    Joined:
    Jul 8, 2005
    Messages:
    2,027
    Likes Received:
    0
    Trophy Points:
    255
    Semi-colon.

    That didn't take me long, since I get those so often, I instinctively check for those almost right away.



     
  12. ModeratelyConfused

    ModeratelyConfused Banned

    Joined:
    Sep 12, 2006
    Messages:
    3,982
    Likes Received:
    0
    Trophy Points:
    0
    It's been a while since I've done any programming, but that's what stuck out the most.
     
  13. Dondrei

    Dondrei IncGamers Member

    Joined:
    Aug 1, 2005
    Messages:
    36,855
    Likes Received:
    30
    Trophy Points:
    467
    Nah, I thought of that but I'm planning to use the same variable for a number of different states.

    Alright, even I got that one.

    Shut up. Anyway, it's funny you should mention that because I'm still used to QBasic which doesn't have that silly "==" convention.



     

Share This Page