Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
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
  #2  
Old 05-18-2012, 09:12 PM
Devil_Lord2 Devil_Lord2 is offline
David K?
Devil_Lord2's Avatar
Join Date: Apr 2011
Location: PA, MD.
Posts: 643
Devil_Lord2 can only hope to improve
Quote:
Originally Posted by Tigairius View Post
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.
I'm only posting on this thread because I find it useful, but I'd like to point out, you should not assume someone thinks it is easier to read something as confusing as that.

I get up to the question mark which then confuses me...
I don't know how much he knows about programming or math,
but some things that may be common sense to some programmers
may not be as such to those just getting into the scene.

That and we all have certain skills inside the language we are good at
and others we've never bothered to touch.

I think you mean to say easier to read all at once,
rather than easier to comprehend? :x

It takes the system more time to read 20 lines when it can read 4...
Anyway, positive reputing your post explaining sign to him, I believe
most people would not take the time to do something like that.
__________________

Digital Media Artist - David K? </3 (UnLoved)
www.davidkrout.com
www.twitch.com/DavidKkz




Last edited by Devil_Lord2; 05-18-2012 at 09:12 PM.. Reason: When I can give it.
Reply With Quote
  #3  
Old 05-18-2012, 10:01 PM
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 Devil_Lord2 View Post
I get up to the question mark which then confuses me...
The question mark is called the ternary operator. It is basically like an if-statement.
Here it is written in English:
RESULT = BOOLEAN ? DO THIS : OTHERWISE DO THIS;

A boolean is simply a statement or value that is either true or false.

Now I'll show you an example of converting an if-else statement into ternary.

PHP Code:
if (this.counter >= 4) {
  
findImg(3).rotation 3;
}else {
  
findImg(3).rotation = -3;

Could essentially be written as the following:
findImg(3).rotation = this.counter >= 4 ? 3 : -3;

The red text is the BOOLEAN. If it's true, it will return/execute whatever is in blue, if it's false, it'll return/execute purple.
__________________


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


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 10:26 PM.


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