Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Using return; to end a script (https://forums.graalonline.com/forums/showthread.php?t=64872)

Yen 03-21-2006 10:10 PM

Using return; to end a script
 
Lately, I've been getting lazy and using 'if (condition) return;' instead of piling up the if (condition) { if (condition) { if (condition) { } } }
Is there any harm that can be caused by doing this?

For example..
PHP Code:

function onActionDamage(dmg,from,fromguild) {
  if (
player.guild == fromguild && player.guild.length() > 0) return;
  if (
player.account == from) return;
  if (
client.allies.index(from) >= 0) return;
  
client.hp -= dmg;


Instead of..
PHP Code:

function onActionDamage(dmg,from,fromguild) {
  if (
player.guild != fromguild || player.guild.length <= 0) {
    if (
player.account != from) {
      if (
client.allies.index(from) == -1) {
        
client.hp -= dmg;
      }
    }
  }



Skyld 03-21-2006 10:17 PM

Quote:

Originally Posted by Yen
Lately, I've been getting lazy and using 'if (condition) return;' instead of piling up the if (condition) { if (condition) { if (condition) { } } }
Is there any harm that can be caused by doing this?

For example..
PHP Code:

function onActionDamage(dmg,from,fromguild) {
  if (
player.guild == fromguild && player.guild.length() > 0) return;
  if (
player.account == from) return;
  if (
client.allies.index(from) >= 0) return;
  
client.hp -= dmg;


Instead of..
PHP Code:

function onActionDamage(dmg,from,fromguild) {
  if (
player.guild != fromguild || player.guild.length <= 0) {
    if (
player.account != from) {
      if (
client.allies.index(from) == -1) {
        
client.hp -= dmg;
      }
    }
  }



No harm at all, although, it doesn't end the script - it just stops the current function from being executed further.

Loriel 03-21-2006 10:37 PM

return; can be used as the first line of a script to comment it out!

ZeLpH_MyStiK 03-22-2006 06:44 AM

Quote:

Originally Posted by Loriel
return; can be used as the first line of a script to comment it out!

As well as break; =O


All times are GMT +2. The time now is 01:43 AM.

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