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)

Gambet 03-31-2007 07:53 AM

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:

Bl0nkt 03-31-2007 08:07 AM

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:

Looks fine to me

killerogue 03-31-2007 08:32 AM

Quote:

Originally Posted by Bl0nkt (Post 1294900)
Looks fine to me

You wonder why scripters hate looking at your scripts Hachi?

:rolleyes:

Chandler 03-31-2007 08:51 AM

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); 
  } 


Angel_Light 03-31-2007 09:08 AM

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.

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 ^^

Rapidwolve 04-06-2007 10:38 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 thought that was directed to me x.x

Chompy 04-06-2007 10:40 PM

Quote:

Originally Posted by Rapidwolve (Post 1297498)
I thought that was directed to me x.x

Thread revival xD

Inverness 04-07-2007 03:55 AM

Quote:

Originally Posted by Chompy (Post 1295060)
return NULL; is just to clear out that it is not returning to a function nor returning a value.

Null IS a value, zero actually. You could just do return; anyways.

And I think Stefan should make the compiler optimize if (var == true) since that looks nicer than if (var) which makes me think of the horrors of GS1.

JkWhoSaysNi 04-07-2007 04:13 AM

Except Gscipt isn't compiled it's interpreted. If it were compiled then the compiler could optimise the statement (by turning it into if (var) ) but since it's interpreted I don't think theres any way to do it.

Anyway, the difference in speed is negligible. Just use if (var == true) if it makes it easier to read.

godofwarares 04-07-2007 04:17 AM

Everyone has their own style of coding, and they can read it. It doesn't matter if other people can't. I style similar to Skyld's styling, mainly because I find his scripts readable and he kinda pushed me to it :P

Inverness 04-07-2007 04:35 AM

GScript is not interpreted, its Compiled when you save the script. Thats how scripts are sent to the client Pre-Compiled like Stefan said. Unless Stefan has a different definition of Compiled.

Twinny 04-07-2007 05:49 AM

I think they are optimised a bit and compiled into byte code.

godofwarares 04-07-2007 02:14 PM

Its compiled into byte code, because they're all stored on your computer if you look closely enough.

Every time you add yourself a weapon, that compiled code goes directly into your computer, probably to lessen the load on the server.

cbk1994 04-07-2007 04:32 PM

if (var) always reminded me of GS1 ... I still have nightmares about that.

Inverness 04-07-2007 09:27 PM

PHP Code:

if (playerchats) {
  
tokenize #c;
  
if (strequals(#t(0),kill:)) {
    
with (getplayer(#t(1))) {
      
playerhearts 0;
    }
  }



JkWhoSaysNi 04-07-2007 10:09 PM

Quote:

Originally Posted by Inverness (Post 1297588)
GScript is not interpreted, its Compiled when you save the script. Thats how scripts are sent to the client Pre-Compiled like Stefan said. Unless Stefan has a different definition of Compiled.

I stand corrected. I always thought it was just interpreted.

The compiler could potentially optimise the code then.

Skyld 04-07-2007 10:42 PM

Quote:

Originally Posted by JkWhoSaysNi (Post 1297726)
I stand corrected. I always thought it was just interpreted.

The compiler could potentially optimise the code then.

Scripts are folded when they are compiled so that they are more efficient.

cbk1994 04-08-2007 04:42 AM

I would find it annoying if I wrote

PHP Code:

if ( var == 

and it changed it to
PHP Code:

if ( var == true 


zokemon 04-08-2007 04:48 AM

Usually the ammount of styling and the importance of a scripter's styling to himself usually reflects his skill with Graal coding.

Pretty hard to do complex scripts if you have horrible spacing ;)

Inverness 04-08-2007 05:02 AM

Quote:

Originally Posted by zokemon (Post 1297907)
Usually the ammount of styling and the importance of a scripter's styling to himself usually reflects his skill with Graal coding.

Pretty hard to do complex scripts if you have horrible spacing ;)

Irrelevant if your typing speed is excellent.

xXziroXx 04-08-2007 07:58 PM

I, too, think that example A looks better then example B.

A: if (var == true) { .... }
B: if (var) { .... }

Rapidwolve 04-08-2007 09:36 PM

Quote:

Originally Posted by xXziroXx (Post 1298117)
I, too, think that example A looks better then example B.

A: if (var == true) { .... }
B: if (var) { .... }

Thats how I had it on my script first, I forgot why I changed it

cbk1994 04-10-2007 04:29 AM

Quote:

Originally Posted by xXziroXx (Post 1298117)
I, too, think that example A looks better then example B.

A: if (var == true) { .... }
B: if (var) { .... }

C:
PHP Code:

if ( var == true )
{
    ...


C seems better than both ^^

xXziroXx 04-10-2007 01:23 PM

Quote:

Originally Posted by cbkbud (Post 1298646)
C:
PHP Code:

if ( var == true )
{
    ...


C seems better than both ^^

No way! I only make new lines for brackets on functions. And I just dont like that way of spacing :cry:

JkWhoSaysNi 04-10-2007 04:07 PM

Me either. The spaces inside the ( brackets offend me too ;)

Heres how I do it:

PHP Code:

if (var) {
       ...


i guess if (var) has more meaning if you name your boolean variables as verbs as I tend to do e.g. if (finished)


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

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