PDA

View Full Version : A Few Functions For Checking


Kyranki
01-12-2008, 05:43 AM
/*
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:


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


As opposed to:


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):
public function hasFunc(func) {
return (temp.func in this.getfunctions());
}

Chompy
01-12-2008, 06:05 PM
I have just one comment.

Instead of all the return true/return false, you can do something like (for example):
public function hasFunc(func) {
return (temp.func in this.getfunctions());
}


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


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
hehe :p

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

But...

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 :).
public function hasVar(var) {
return isValidVar(temp.var) && (temp.var in this.getdynamicvarnames());
}

Chompy
01-13-2008, 01:46 PM
You b****** you! Must you always Chompy? >_<

You know I have to :) <3

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 :).
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)