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
-
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
-
You have to register a link in the Bot class, either directly with a line like below in 0.4
$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.
-
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)
-
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 ?
-
put
$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
$classvar = new ClassA(&$bot);
then u can call function in the class from other classes useing $this -> bot -> linktoa
-
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.