Programming help

Dondrei

Diabloii.Net Member
Programming help

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

spritestate = 0;

if (spritestate = 0) {spritestate = 1;} else {spritestate = 0;}
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.
 

AJK

Diabloii.Net Member
Try
Code:
spritestate = 0;

if (spritestate [highlight]==[/highlight] 0) {spritestate = 1;} else {spritestate = 0;}
 

myleftfoot

Diabloii.Net Member
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.


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



 

SaroDarksbane

Diabloii.Net Site Pal
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.
 

SaroDarksbane

Diabloii.Net Site Pal
lol, I can't believe I didn't pick that up at first. It's a classic!
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.



 

myleftfoot

Diabloii.Net Member
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++)[b]; WHAT IS THIS DOING HERE?!?!? :azn: [/b] {
   // Do a bunch of stuff here
}
They'll spend hours trying to figure out why their code isn't working.
These things can be shockingly time wasting :smiley:



 

bladesyz

Diabloii.Net Member
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.
Semi-colon.

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



 

Dondrei

Diabloii.Net Member
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.
Nah, I thought of that but I'm planning to use the same variable for a number of different states.

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.
Alright, even I got that one.

10 ?"DONDREI IS TEH DUM"
20 GOTO 10

I thought you already had a thread for your failures. ;-)
Shut up. Anyway, it's funny you should mention that because I'm still used to QBasic which doesn't have that silly "==" convention.



 
Top