BeBot - An Anarchy Online and Age Of Conan chat automaton

Development => Coding and development discussion => Topic started by: onekman on April 23, 2008, 05:04:30 pm

Title: Tranferring data between modules
Post by: onekman on April 23, 2008, 05:04:30 pm
Since I'm not the world biggest PHP genious, I need help with following :

I got a own developed class, let's call it ClassA. From this class I set a Flag(true/false), and I need this value to be accessable from ClassB.

How is it doable in a propper way ?

regards
1k
Title: Re: Tranferring data between modules
Post by: Alreadythere on April 23, 2008, 06:10:49 pm
You have to register a link in the Bot class, either directly with a line like below in 0.4
Code: [Select]
$classvar = new ClassA(&$bot);
$bot -> linktoa = &$classvar;

class ClassA {}
Then you can simple do $this -> bot -> linktoa -> variablename to access the field.

In SVN we got a dedicated function to register those links.
Title: Re: Tranferring data between modules
Post by: Glarawyn on April 24, 2008, 12:25:25 am
You could also use the settings interface if that makes sense for you.

See the BeBot Developer's Handbook (http://bebot.link/wiki/developers_handbook)
Title: Re: Tranferring data between modules
Post by: onekman on April 24, 2008, 04:49:54 pm
Alreadythere : You wrote I had to register a link in the Bot class. When you says Botclass you mean the class I made or in the Bot main module ?

Title: Re: Tranferring data between modules
Post by: Temar on April 24, 2008, 05:03:47 pm
put

Code: [Select]
$bot -> linktoa = &$classvar;

renameing linktoa to wateva u want
and classvar to the class name

and put this in your module before the class so its outside the class but after the line

Code: [Select]
$classvar = new ClassA(&$bot);

then u can call function in the class from other classes useing $this -> bot -> linktoa
Title: Re: Tranferring data between modules
Post by: Blueeagle on May 17, 2008, 06:52:07 pm
It is my opinion that values that more than one module need access to should have this stored in a core module and export the value via the regular api $this->bot->core('module')

The prefered method is to use settings or preferences. If the flag is of a global nature it should use settings and if it's a flag that's set on a per user basis it should use a preference.

You can create your own database table to hold the value ofcourse, but the framework for settings and preferences are in place so we think they should be used.
SimplePortal 2.3.7 © 2008-2024, SimplePortal