Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12  
Old 05-18-2012, 04:02 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by greggiles View Post
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.3this.counter == "RotateForwards" "RotateBackwards");
  
this.counter ++;
}

function 
onRotateForwards() {
  
findImg(3).rotation += 0.05;
  
scheduleEvent(0.3this.counter == ?  "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 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.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 05-18-2012 at 04:16 AM..
Reply With Quote
 


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 On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:16 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.