Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-12-2008, 05:43 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
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.
__________________
Stan.
Reply With Quote
  #2  
Old 01-12-2008, 07:01 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
The function checking one...maybe... but definitely not one for checking an object for variables. Seems like an unnecessary process for a simple operation.
Reply With Quote
  #3  
Old 01-12-2008, 08:47 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
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());

__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #4  
Old 01-12-2008, 06:05 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by napo_p2p View Post
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

I just had to edit it :o
(<3)
__________________
Reply With Quote
  #5  
Old 01-13-2008, 07:06 AM
Kyranki Kyranki is offline
Freelance Coder
Join Date: Aug 2007
Location: At the end of the rainbow, in the pot of gold.
Posts: 202
Kyranki is on a distinguished road
Send a message via AIM to Kyranki Send a message via MSN to Kyranki
Quote:
Originally Posted by Twinny View Post
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 View Post
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

I just had to edit it :o
(<3)
You b****** you! Must you always Chompy?
__________________
Stan.
Reply With Quote
  #6  
Old 01-13-2008, 07:49 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
Quote:
Originally Posted by Chompy View Post
hehe

I just had to edit it :o
(<3)
Haha, good stuff :P.

But...
Quote:
Originally Posted by Chompy View Post
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());

__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #7  
Old 01-13-2008, 01:46 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Kyranki View Post
You b****** you! Must you always Chompy?
You know I have to <3

Quote:
Originally Posted by napo_p2p View Post
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
__________________
Reply With Quote
  #8  
Old 01-13-2008, 08:31 PM
Inverness Inverness is offline
Incubator
Inverness's Avatar
Join Date: Aug 2004
Location: Houston, Texas
Posts: 3,613
Inverness is a jewel in the roughInverness is a jewel in the rough
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)
__________________
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 07:00 AM.


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