Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Clean Coding - Common Sense (https://forums.graalonline.com/forums/showthread.php?t=73158)

godofwarares 03-31-2007 01:44 PM

Quote:

Originally Posted by Angel_Light (Post 1294912)
Yes this has happened to me too *sneeze*TheFox*sneezes* I just used the Servers style command

/style Type Name

Like when Fox made a weapon I couldnt read I did

/Style weapon -FoxTest

it's not "my" style but it organizes the code.

Simple yet effective :p

Skyld 03-31-2007 02:02 PM

Quote:

Originally Posted by Chandler (Post 1294909)
I'd do this:
PHP Code:

public function Hurt(hurtDamageattackersAccounthurtGani)
  if (
this.clientr.hp && !this.clientr.dead && !level.nopk && !this.client.nopk)
  {
  
this.clientr.hp -= abs(temp.hurtDamage);  
  if (
temp.hurtGani
    
this.setAni("hurt""");
  
clientr.lastattacker temp.attackersAccount;
  if (
this.clientr.hp <= 0
    
this.doDeath(temp.attackersAccount);
  
this.showHp(7);
  }
public function 
doDeath(attackersAccount)
  {
  
this.clientr.dead true;
  
this.clientr.hp 0;
  
this.Kill(temp.attackersAccount); 
  } 


Ugh, that makes my eyes bleed. Your brackets should be inline with the block, not with the contents. You've missed out a load of brackets anyway, and you've mixed all sorts of conditional checks which are totally unrelated to each other in one line. :/ Bleugh.

xXziroXx 03-31-2007 02:12 PM

Quote:

Originally Posted by Skyld (Post 1294941)
Ugh, that makes my eyes bleed. Your brackets should be inline with the block, not with the contents. You've missed out a load of brackets anyway, and you've mixed all sorts of conditional checks which are totally unrelated to each other in one line. :/ Bleugh.

I second that..

cbk1994 03-31-2007 02:24 PM

Quote:

Originally Posted by Rapidwolve (Post 1294873)
I recently have been practicing better organization and clean coding in my scripts, heres a snippet.

PHP Code:

public function Hurt(damageattackerhurtani){
  
temp.conditionsok = ((this.clientr.hp && this.clientr.dead == false && level.nopk == false && this.client.nopk == false) ? true false);
   if (
temp.conditionsok){
       if (
temp.damage => this.clientr.hp) {
        
this.clientr.hp 0;
        
this.Kill(temp.attacker); 
        
this.showHp(7);
        return;
       }
       if (
temp.hurtanithis.setani("hurt"null);
          
clientr.lastattacker temp.attacker;
          
this.clientr.hp -= abs(temp.damage);
          
this.showHp(7);
    }
    return;



Looks nice, but personally I prefer
PHP Code:

if (temp.hurtani == true

instead of
PHP Code:

if (temp.hurtani

and I'd recommend braces for everything anyway.

Hachi ... I'd be scared to see your scripting.

Rapidwolve 03-31-2007 07:34 PM

Quote:

Originally Posted by Gambet (Post 1294895)
Yeah, your old method of not styling at all and scripting like this:

PHP Code:

function onCreated(){
player.chat="Rapid's styling sucks major wang";
setTimer(1);
}

function 
onTimeOut(){
this.yourstylingoldstylingsucks;;
chat="You grouped everything together without any spacing";
echo(
"And it was very annoying to read");
setTimer(1);



Or something like that....



It was very annoying and barely legible.

:frown:

I never styled like that x.x

Chandler 03-31-2007 07:37 PM

Quote:

Originally Posted by Skyld (Post 1294941)
Ugh, that makes my eyes bleed. Your brackets should be inline with the block, not with the contents. You've missed out a load of brackets anyway, and you've mixed all sorts of conditional checks which are totally unrelated to each other in one line. :/ Bleugh.

*****.

Chompy 03-31-2007 08:26 PM

Someone (Well, a couple) told me to change my styling so...

PHP Code:

public function Hurt(damageattackerhurtani) {
  
temp.conditionsok = ((this.clientr.hp && this.clientr.dead == false && level.nopk == false && this.client.nopk == false) ? true false);
  if (
temp.conditionsok) {

    if (
temp.damage => this.clientr.hp) {
      
this.clientr.hp 0;
      
this.Kill(temp.attacker); 
      
this.showHp(7);
      return 
NULL;
    }
    if (
temp.hurtani)
      
this.setani("hurt"NULL);

    
this.clientr.lastattacker temp.attacker;
    
this.clientr.hp -= abs(temp.damage);
    
this.showHp(7);
    return 
NULL;
  }


(Based of RW's script)

Angel_Light 03-31-2007 08:31 PM

I don't care what people think of my styling it's makes scripting easier for me and allows ME to read it better/quicker. But when ever I do post a snippet I usually do use the /style.

cbk1994 03-31-2007 09:42 PM

Quote:

Originally Posted by Chompy (Post 1295035)
Someone (Well, a couple) told me to change my styling so...

PHP Code:

public function Hurt(damageattackerhurtani) {
  
temp.conditionsok = ((this.clientr.hp && this.clientr.dead == false && level.nopk == false && this.client.nopk == false) ? true false);
  if (
temp.conditionsok) {

    if (
temp.damage => this.clientr.hp) {
      
this.clientr.hp 0;
      
this.Kill(temp.attacker); 
      
this.showHp(7);
      return 
NULL;
    }
    if (
temp.hurtani)
      
this.setani("hurt"NULL);

    
this.clientr.lastattacker temp.attacker;
    
this.clientr.hp -= abs(temp.damage);
    
this.showHp(7);
    return 
NULL;
  }


(Based of RW's script)

I've never seen of return NULL. Any different from return false;?

--

There's more to scripting than you reading it. It needs to be legible for others too.

Chompy 03-31-2007 09:43 PM

Quote:

Originally Posted by cbkbud (Post 1295059)
I've never seen of return NULL. Any different from return false;?

return NULL; is just to clear out that it is not returning to a function nor returning a value.

Kristi 03-31-2007 09:56 PM

Quote:

Originally Posted by cbkbud (Post 1294945)
Looks nice, but personally I prefer
PHP Code:

if (temp.hurtani == true

instead of
PHP Code:

if (temp.hurtani

and I'd recommend braces for everything anyway.

Hachi ... I'd be scared to see your scripting.

What? if(something == true)? ::hits::

JkWhoSaysNi 03-31-2007 09:59 PM

checking "if (var == true)" is redundant unless you're not sure on the type of the variable.

cbk1994 04-01-2007 12:58 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1295069)
checking "if (var == true)" is redundant unless you're not sure on the type of the variable.

Works fine ... to me it seems simpler.

if ( var == 1 )

better?

JkWhoSaysNi 04-01-2007 01:00 AM

if (var) is simpler and more efficient.

when you do if (var == true) the interpreter is basically doing 2 checks.

cbk1994 04-01-2007 03:14 PM

I see. I'll try to get used to that, though I suppose it doesn't matter that much now that I see it ^^


All times are GMT +2. The time now is 10:51 AM.

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