Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-24-2010, 07:00 PM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
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!
Reply With Quote
  #2  
Old 01-24-2010, 07:22 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
If a class only is joined on clientside, it breaks if it has the //#CLIENTSIDE text in it.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #3  
Old 01-24-2010, 07:27 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.

Last edited by DustyPorViva; 01-24-2010 at 07:50 PM..
Reply With Quote
  #4  
Old 01-24-2010, 07:40 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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();

__________________
Quote:
Reply With Quote
  #5  
Old 01-24-2010, 08:21 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Why not just join the class serverside?
__________________
Reply With Quote
  #6  
Old 01-24-2010, 08:49 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #7  
Old 01-24-2010, 08:52 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by DustyPorViva View Post
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.
__________________
Reply With Quote
  #8  
Old 01-24-2010, 09:05 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
Why not just join the class serverside?
I found this solution to be successful when I had problems with joining classes clientside.
Reply With Quote
  #9  
Old 01-24-2010, 09:32 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
A solution is still preferred if you start joining classes to GUI's.
Reply With Quote
  #10  
Old 01-24-2010, 09:44 PM
Immolate Immolate is offline
Indigo
Join Date: Dec 2009
Posts: 322
Immolate is on a distinguished road
Quote:
Originally Posted by DustyPorViva View Post
A solution is still preferred if you start joining classes to GUI's.
Yeah, I agree with this.
Reply With Quote
  #11  
Old 01-24-2010, 10:44 PM
thatdwarf thatdwarf is offline
Former UN Dev Admin
Join Date: Nov 2005
Posts: 42
thatdwarf is on a distinguished road
I tried these solutions, but it still refuses to work.

Any other suggestions?
Reply With Quote
  #12  
Old 01-24-2010, 10:45 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:00 AM.


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