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 06-23-2007, 08:54 AM
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
Function Import

I had requested this feature along time ago and the new function objects have made it possible now.

This will create function pointers in an object. Variable list:
fromobj - Object, The object you want to import functions from.
toobj - Object, The object you want to import functions to.
fromprefix - String, Only import functions starting with this text. If null, all functions imported.
toprefix - String, Imported functions will be prefixed with this.
events - Boolean, Should functions starting with "on" be included in the operations?
PHP Code:
public function import(fromobjtoobjfromprefixtoprefixevents) {
  
temp.vars 0;
  
temp.0;
  
  if (
fromobj.type() != || toobj.type() != 2) {
    echo(
"System: Import Error");
    return;
  }
  
vars fromobj.getFunctions();
  if (
fromprefix != null) {
    for (
ivars) {
      if (
i.starts("on") && events == false)
        continue;
      if (
fromobj.(@ i).starts(fromprefix)) {
        if (
toprefix == null) {
          
toobj.(@ i) = fromobj.(@ i);
          
toobj.importedfunctions.add(i);
        }
        else {
          
toobj.(@ toprefix i) = fromobj.(@ i);
          
toobj.importedfunctions.add(toprefix i);
        }
      }
    }
  }
  else {
    for (
ivars) {
      if (
i.starts("on") && events == false)
        continue;
      if (
toprefix == null) {
        
toobj.(@ i) = fromobj.(@ i);
        
toobj.importedfunctions.add(i);
      }
      else {
        
toobj.(@ toprefix i) = fromobj.(@ i);
        
toobj.importedfunctions.add(toprefix i);
      }
    }
  }
}
public function 
deport(obj) {
  
temp.vars 0;
  
temp.0;
  
  
vars obj.importedfunctions;
  for (
ivars) {
    
obj.(@ i) = null;
  }

Example:
PHP Code:
// WEAPON: InverTest
function testf(text) {
  echo(
"TESTF: " text);
}
function 
test2(text) {
  echo(
"Test2: " text);

PHP Code:
// WEAPON: InverTest2
function onCreated() {
  
System.import(InverTestthis"test"nullfalse); // importing functions that start with 'test'
  
testf("ZOMG");
  
test2("RAWR");
  
System.deport(this); // removes imported functions

PHP Code:
// Example script
function onCreated() {
  
System.import(MudControlthisnull"mud_"false);
  
// Importing all functions from MudControl and prefixing with mud_ to remove conflict.

I've also noted that using this method can be used even if the imported functions are not public.
__________________

Last edited by Inverness; 06-23-2007 at 09:06 AM..
Reply With Quote
  #2  
Old 06-23-2007, 09:20 AM
coreys coreys is offline
N-Pulse Assistant Manager
coreys's Avatar
Join Date: Mar 2005
Posts: 2,180
coreys has a spectacular aura about
Send a message via AIM to coreys Send a message via MSN to coreys Send a message via Yahoo to coreys
Awesome stuff, Inver...
Will you bear my children?
__________________

Quote:
*SlikRick: so should I even ask about your aim status?
*Xor: well if you want to
*Xor: but i am LARPING
*SlikRick: While on a computer?
*Xor: yes
*Xor: in my living room
*SlikRick: ahh
*Xor: i have a fort setup to hide from beasts
Reply With Quote
  #3  
Old 06-23-2007, 05:24 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
Really, reallly, really Nice Invern
__________________
Reply With Quote
  #4  
Old 06-23-2007, 06:09 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
ego++
__________________
Reply With Quote
  #5  
Old 06-23-2007, 09:53 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Quote:
Originally Posted by Inverness View Post
ego++
NPC Code:
if (this.thread) {
temp.e = ego;
findplayer("Inverness").ego++;
}
if (findplayer("Inverness").ego > e) findplayer("Inverness").badadditude--;



Yay or nay?
__________________
Do it with a DON!
Reply With Quote
  #6  
Old 06-24-2007, 11:46 AM
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
Quote:
Originally Posted by zokemon View Post
NPC Code:
if (this.thread) {
temp.e = ego;
findplayer("Inverness").ego++;
}
if (findplayer("Inverness").ego > e) findplayer("Inverness").badadditude--;



Yay or nay?
What is "additude"?
__________________
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 11:56 PM.


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