Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Weapon -> Class (https://forums.graalonline.com/forums/showthread.php?t=134257757)

thatdwarf 01-24-2010 07:00 PM

Weapon -> Class
 
Hey everybody,

I'm having a bit of a tough time here. I've tried seperating the GUI initialization lines from my weapon script and placed them in a class.

Here's the general layout:

Weapon Script:
PHP Code:

/*
   class functions:
      createGUI() - public function that holds the GUI creation lines
      toggle(status) - public function that shows/hides the GUI windows
*/

//#CLIENTSIDE
this.join("gui_design");

function 
onCreated() {
  
this.on false;
  
createGUI();
  
toggle(this.on);
}

function 
onWeaponFired() {
  
this.on = !this.on;
  
player.chat = (this.on) ? "On":"Off";
  
toggle(this.on);


Class Script
PHP Code:

//#CLIENTSIDE
public function toggle(status) {
  if(
status) {
    
Menu.show();
    
Stats.show();
  }else{
    
Menu.hide();
    
Stats.hide();
  }
}

public function 
createGUI() {
  
//GUI Lines Here


I also have each button calling an appropriate function using thiso.catchevent(). Should those functions also be public?

The problem that I am having is if the player has just logged on and tries to turn on the NPC, the status switches, but the GUI does not hide/show. If I hit "Apply" on the script window, it works.

This is obviously very inconvenient, and indicates something is wrong. Any suggestions?


I also plan on using a TStaticVar, defined in another class, to allow changes to the GUI to be extremely easy. But I'm having trouble passing the TStaticVar inbetween scripts.


Thanks in advance!

xXziroXx 01-24-2010 07:22 PM

If a class only is joined on clientside, it breaks if it has the //#CLIENTSIDE text in it.

DustyPorViva 01-24-2010 07:27 PM

This is because classes don't join immediately when you log on, but the script continues. This is highly annoying, as scripts that rely on a class will break on initiation.

You might be able to do something like this:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.join("gui_design");
  while (!
isinclass("gui_design")) sleep(0.05);
  
this.on false;
  
createGUI();
  
toggle(this.on);
}

function 
onWeaponFired() {
  
this.on = !this.on;
  
player.chat = (this.on) ? "On":"Off";
  
toggle(this.on);


I was going to suggest somehow using waitfor() to make the script wait until the class is successfully joined, but I'm not entirely sure how waitfor() is used, and if it can capture when a class joins a script.

I'm not even sure if what I suggested will work, because the class may never join if it is waiting for the next 'frame'. In that case this MIGHT work:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  while (!
isinclass("gui_design")) {
    
this.join("gui_design");
    
sleep(0.05);
  }
  
this.on false;
  
createGUI();
  
toggle(this.on);
}

function 
onWeaponFired() {
  
this.on = !this.on;
  
player.chat = (this.on) ? "On":"Off";
  
toggle(this.on);


Might need to wait for someone more experience dealing with catching/waiting for functions to deal with this, however.

fowlplay4 01-24-2010 07:40 PM

I personally just do the following:

Class Script:

PHP Code:

//#CLIENTSIDE
function onInitGUI() {
  
createGUI();


Weapon script:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.scheduleevent(0.05"InitGUI""");


I know for developing purposes you want to update it, and see the changes immediately but in the end you should be aiming for creating it only when it's needed.

I.e:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.join("gui_design");
}

function 
onWeaponFired() {
  if (!
isGUICreated()) {
    
createGUI();
  }
  
toggleGUI();



cbk1994 01-24-2010 08:21 PM

Why not just join the class serverside?

DustyPorViva 01-24-2010 08:49 PM

Quote:

Originally Posted by cbk1994 (Post 1552137)
Why not just join the class serverside?

Wouldn't fix the delay problem as that's how I deal with classes and still have the same problem.

cbk1994 01-24-2010 08:52 PM

Quote:

Originally Posted by DustyPorViva (Post 1552141)
Wouldn't fix the delay problem as that's how I deal with classes and still have the same problem.

Sure it does, I've done it many times.

Immolate 01-24-2010 09:05 PM

Quote:

Originally Posted by cbk1994 (Post 1552137)
Why not just join the class serverside?

I found this solution to be successful when I had problems with joining classes clientside.

DustyPorViva 01-24-2010 09:32 PM

A solution is still preferred if you start joining classes to GUI's.

Immolate 01-24-2010 09:44 PM

Quote:

Originally Posted by DustyPorViva (Post 1552156)
A solution is still preferred if you start joining classes to GUI's.

Yeah, I agree with this.

thatdwarf 01-24-2010 10:44 PM

I tried these solutions, but it still refuses to work.

Any other suggestions?

DustyPorViva 01-24-2010 10:45 PM

PHP Code:

/*
   class functions:
      createGUI() - public function that holds the GUI creation lines
      toggle(status) - public function that shows/hides the GUI windows
*/
function onCreated() {
  
this.join("gui_design");
}
//#CLIENTSIDE
function onCreated() {
  
this.on false;
  
createGUI();
  
toggle(this.on);
}

function 
onWeaponFired() {
  
this.on = !this.on;
  
player.chat = (this.on) ? "On":"Off";
  
toggle(this.on);


PHP Code:

//#CLIENTSIDE
public function toggle(status) {
  if(
status) {
    
Menu.show();
    
Stats.show();
  }else{
    
Menu.hide();
    
Stats.hide();
  }
}

public function 
createGUI() {
  
//GUI Lines Here


Though we're missing some details, what is Menu and Stats?


All times are GMT +2. The time now is 02:35 AM.

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