Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   A Few Functions For Checking (https://forums.graalonline.com/forums/showthread.php?t=78316)

Kyranki 01-12-2008 05:43 AM

A Few Functions For Checking
 
PHP Code:

/*
  This is an object class meaning it needs to be joined to a prior created object such as a TStaticVar() or a weaponNPC.

  And is called as such:

  obj.(function right here without parenthesis)(params)

*/

public function hasFunc(func) {
  if (
func in this.getfunctions())
    return 
true;
  return 
false;
}
public function 
isDynamicFunc(func) {
  if (
func in this.getdynamicvarnames())
    return 
true;
  return 
false;
}
public function 
hasVar(var) {
  if (var 
in this.getdynamicvarnames()) {
    if (
isValidVar(var))
      return 
true;
  }
  return 
false;
}
public function 
isValidVar(var) {
  if (
this.(@ var) != null)
    return 
true;
  return 
false;


Hopefully, these will make it easier for scripters here and there to code their systems with ease and not get confuse when doing a crap load of var checks, and etc etc.

I often get confused when doing a crapload of checks and I've always found it easier to do:

PHP Code:

if (!obj.hasVar(var))
  continue; 

As opposed to:

PHP Code:

if (obj.(@ var) == null)
  continue; 

I think it looks nicer/neater but maybe I'm just being picky. Use as you feel necessary.

Twinny 01-12-2008 07:01 AM

The function checking one...maybe... but definitely not one for checking an object for variables. Seems like an unnecessary process for a simple operation.

napo_p2p 01-12-2008 08:47 AM

I have just one comment.

Instead of all the return true/return false, you can do something like (for example):
PHP Code:

public function hasFunc(func) {
  return (
temp.func in this.getfunctions());



Chompy 01-12-2008 06:05 PM

Quote:

Originally Posted by napo_p2p (Post 1369287)
I have just one comment.

Instead of all the return true/return false, you can do something like (for example):
PHP Code:

public function hasFunc(func) {
  return (
temp.func in this.getfunctions());



PHP Code:

public function hasFunc(func) {
  return (
func in this.getfunctions());
}
public function 
isDynamicFunc(func) {
  return (
func in this.getdynamicvarnames());
}
public function 
hasVar(var) {
  if (var 
in this.getdynamicvarnames())
    return 
isValidVar(var);
}
public function 
isValidVar(var) {
  return (
this.(@ var) != null);
}
public function 
isObj(obj) {
  return (
obj.type() == 2);
}
public function 
isEditVar(var) {
  return (var 
in this.geteditvarnames());


hehe :p

I just had to edit it :o
(<3)

Kyranki 01-13-2008 07:06 AM

Quote:

Originally Posted by Twinny (Post 1369284)
The function checking one...maybe... but definitely not one for checking an object for variables. Seems like an unnecessary process for a simple operation.

I couldn't think of much else that would be helpful to someone. :o

Quote:

Originally Posted by Chompy (Post 1369315)
PHP Code:

public function hasFunc(func) {
  return (
func in this.getfunctions());
}
public function 
isDynamicFunc(func) {
  return (
func in this.getdynamicvarnames());
}
public function 
hasVar(var) {
  if (var 
in this.getdynamicvarnames())
    return 
isValidVar(var);
}
public function 
isValidVar(var) {
  return (
this.(@ var) != null);
}
public function 
isObj(obj) {
  return (
obj.type() == 2);
}
public function 
isEditVar(var) {
  return (var 
in this.geteditvarnames());


hehe :p

I just had to edit it :o
(<3)

You b****** you! Must you always Chompy? >_<

napo_p2p 01-13-2008 07:49 AM

Quote:

Originally Posted by Chompy (Post 1369315)
hehe :p

I just had to edit it :o
(<3)

Haha, good stuff :P.

But...
Quote:

Originally Posted by Chompy (Post 1369315)
PHP Code:

public function hasVar(var) {
  if (var 
in this.getdynamicvarnames())
    return 
isValidVar(var);



For that, if the var isn't a dynamic variable, then the function won't return anything :(.

This should do the trick :).
PHP Code:

public function hasVar(var) {
  return 
isValidVar(temp.var) && (temp.var in this.getdynamicvarnames());



Chompy 01-13-2008 01:46 PM

Quote:

Originally Posted by Kyranki (Post 1369438)
You b****** you! Must you always Chompy? >_<

You know I have to :) <3

Quote:

Originally Posted by napo_p2p (Post 1369448)
Haha, good stuff :P.

But...
For that, if the var isn't a dynamic variable, then the function won't return anything :(.

This should do the trick :).
PHP Code:

public function hasVar(var) {
  return 
isValidVar(temp.var) && (temp.var in this.getdynamicvarnames());



:P hehe

Inverness 01-13-2008 08:31 PM

hasfunction() is an existing function of TGraalVar. And returns if an object has the function name you input.

These kinds of things would be useful as custom global functions. (Adding Control-NPC to function lookup)


All times are GMT +2. The time now is 06:45 AM.

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