I am attempting to create player. variables through a player-joined class. If this is not possible, then I suppose that is valuable information, and I will resort to something like clientr. variables, but nonetheless, I thought logically I would be able to create player. variables within a class when it's joined by using this. variables in the class.
I am attaching a class to a player upon log-in in the Control-NPC, as such:
PHP Code:
function onActionPlayerOnline() {
player.join( "foobar" );
}
Afterwards, in the class itself, I am attempting to set the player variables:
PHP Code:
function onCreated() {
this.foo = 1;
this.bar = 2;
}
I have also attempted the following within the class:
PHP Code:
function onCreated() {
if ( this.foo == NULL && this.bar == NULL ) {
createVariables();
}
}
function createVariables() {
this.foo = 1;
this.bar = 2;
}
I have also attempted using a weapon NPC to check the player variables and then consequently call upon a public function within the class to set said player variables:
Weapon NPC:
PHP Code:
function onCreated() {
if ( player.foo == NULL && player.bar == NULL ) {
player.createVariables();
}
}
Class NPC:
PHP Code:
public function createVariables() {
this.foo = 1;
this.bar = 2;
}
I thought this was a simple matter, but I'm not getting any return from what I can tell. Any ideas?
EDIT: Solved. For future reference for all of those rusty folk like myself out there, here is what worked for me:
Control-NPC:
PHP Code:
function onActionPlayerOnline() {
player.join( "foobar" );
if ( player.foo == NULL && player.bar == NULL ) {
player.createVariables();
}
}
Class NPC:
PHP Code:
public function createVariables() {
this.foo = 1;
this.bar = 2;
}