Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Player Classes and Variables (https://forums.graalonline.com/forums/showthread.php?t=134269952)

devilsknite1 05-06-2015 09:39 PM

Player Classes and Variables
 
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;



xAndrewx 05-07-2015 12:50 PM

Because you're referring directly to the player, I'd put the check INSIDE the class. Otherwise you're defying the point of player classes.

Inside the 'foobar' class I'd do the following
HTML Code:

  //Call the check on login
function onCreated() {
  this.createVariables();
}

  //Do the check here
public function createVariables() {
  if (this.foo != null && this.bar != null) return;

  this.foo = 1;
  this.bar = 2;
}



All times are GMT +2. The time now is 08:06 PM.

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