Quote:
Originally Posted by greggiles
Is repetitivness bad?
|
Also, I just wanted to clarify to you: It's bad if the way the code was WRITTEN is repetitive, it doesn't matter if the actual execution of the code is repetitive. Does that make sense?
He means it's repetitive because you have a lot of functions that do, essentially, the exact same thing, when you could've reduced it to one or two functions to complete the task.
One way to have done it without the sine function that is much closer to the way you originally wrote it, is something like this:
PHP Code:
function onRotateBackwards() {
findImg(3).rotation -= 0.05;
scheduleEvent(0.3, this.counter % 4 == 0 ? "RotateForwards" : "RotateBackwards");
this.counter ++;
}
function onRotateForwards() {
findImg(3).rotation += 0.05;
scheduleEvent(0.3, this.counter % 4 == 0 ? "RotateBackwards" : "RotateForwards");
this.counter ++;
}
You can see it accomplishes the same task, using the same exact way, but it's just been condensed into two event functions.
You could even go a step further, and write it somehow like this:
PHP Code:
function onRotateImage() {
temp.direction = this.counter % 8 < 4;
findImg(3).rotation = temp.direction ? (findImg(3).rotation + 0.05) : (findImg(3).rotation - 0.05);
this.counter ++;
scheduleEvent(0.3, "RotateImage");
}
I think you can agree that it's much nicer and easier to read than having 8 different functions to complete the single task.