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 09-08-2017, 07:55 PM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
properly destroying GUI controls?

I'm currently having issues with a custom sign system I am creating. I think the bug exists because the GUI controls aren't being destroyed properly (working theory for right now). This is how I am destroying the controls:

PHP Code:
function DestroyGUI() {
  
hideimg(200);
  
first_object.destroy();
  
second_object.destroy(); 

Both are GuiBitmapCtrl controls which contain other controls. And this seems to work fine when you interact with one sign, but once you touch a second sign the F2 log starts throwing errors.

Quote:
Script: Function first_object.destroy not found in function DestroyGUI of maximus_debug in script of Sign (in level maximus_asinus_test_03.nw at pos (44, 14))

Script: Function second_object.destroy not found in function DestroyGUI of maximus_debug in script of Sign (in level maximus_asinus_test_03.nw at pos (41, 14))
Once this starts to happen the sign starts pulling text from the other sign. I've read through the wiki about a dozen times now, and I still don't understand what I'm doing wrong.
__________________
Save Classic!
Reply With Quote
  #2  
Old 09-12-2017, 12:32 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
For future knowledge this was an issue with how I was calling the next function and not an issue with destroy(). It works as intended.

I would like to know a decent method for destroying a GUI control if the player is warped. If anyone has advice on that I'd like to hear. Thanks!
__________________
Save Classic!
Reply With Quote
  #3  
Old 09-12-2017, 02:13 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I've run into another problem and I'm not entirely certain how to get around it or what is causing it. I am checking if a specific key is pressed when a control is active:
PHP Code:
function CONTROLNAME.onKeyDown(keycodekeytextscancode) {
  if (
keytext == "d") {
    
this.option CONTROLNAME.getselectedrow();
    
CONTROLNAME.destroy();
  }

But for whatever reason this block of code repeats multiple times before exiting the script. This is a problem as obviously the control is deleted, so this.option will be overwritten and return 0.
__________________
Save Classic!
Reply With Quote
  #4  
Old 09-12-2017, 08:43 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
You can use findobject("objectname") to check if an object exists before destroying it.

For clearing out GUIs when you leave a level(assuming you are creating the GUI's in a level script) you can try a serverside onPlayerLeaves(), like so:

PHP Code:
function onPlayerLeaves() {
  if (
player != nullplayer.triggerClient("gui","SomeSystemWeapon","clearcontrols","ControlName");

Then have a system weapon to handle the client trigger:

PHP Code:
//#CLIENTSIDE
function onActionClientside() {
  if (
params[0] == "clearcontrols") {
    if (
params[1] != null) {
      
temp.obj findObject(params[1]);
      if (
temp.obj != nulltemp.obj.destroy();
    }
  }

Other methods could be adding the control name to an array to clear out(along with a level name it should be linked to) and in a System weapon scanning through the array onPlayerEnters() and destroying any controls that exist if the player is not in the level name linked to that control.

For the other issue you can try keeping track of when an object is going to be destroyed. Just so you know, objects can also have dynamic variables assigned to them.

PHP Code:
new GuiControl("Control") {
  
10;
  
width height 100;
  
this.isSomeFlag true;

You can now access Control.isSomeFlag as well as something like:

PHP Code:
echo("Flag State: " Control.isSomeFlag);

// Will echo the same state as above
with (Control) {
  echo(
"Flag State: " this.isSomeFlag);

So with that in mind, you can try something like this:
PHP Code:
function CONTROLNAME.onKeyDown(keycodekeytextscancode) {
  if (
keytext == "d") {
    
// Don't try to destroy if already queued to be destroyed;
    
if (CONTROLNAME.isDestroyed == true) return;

    
this.option CONTROLNAME.getselectedrow();
    
CONTROLNAME.isDestroyed true;
    
CONTROLNAME.destroy();
  }

Reply With Quote
  #5  
Old 09-13-2017, 02:19 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I'm trying to what you suggested, but I am still having issues with the keydown repeating. Maybe showing exactly what I'm doing will shine more light on my problem.

PHP Code:
//this.isDestroyed is set to false inside of say3_options_object
//say3_options_list is set to be the first responder
function say3_options_list.onKeyDown(keycodekeytextscancode) {
  if (
keytext == "d") {
// say3_options_list is inside say3_options_object
    
if (say3_options_object.isDestroyed == true) return; 
    
say3_options_object.isDestroyed true
    
this.option say3_options_list.getselectedrow(); // get row value
    
DestroySay3(); // function to destroy all GUI objects
  
}

After I added your suggestion it only loops twice (before it looped three times). I still don't understand why it loops at all.

Also after testing a little bit it doesn't look like onPlayerLeaves is called, at least if the player uses "unstick me". I am going to look into that a bit more.
__________________
Save Classic!

Last edited by maximus_asinus; 09-13-2017 at 04:39 AM..
Reply With Quote
  #6  
Old 09-13-2017, 04:36 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
Make sure onPlayerLeaves() {} is being used serverside, not clientside.

As for the issue you're encountering with the list selection... sometimes Graal is gonna be Graal. You can try using something other than getselectedrow(), like getselectedid() and assign ID's starting at 1 or such. That way if Graal returns 0 or such you'll know it's not a valid input and to just ignore it.
Reply With Quote
  #7  
Old 09-14-2017, 01:51 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
For future reference, onPlayerLeaves works. When I was joining the class it was on CLIENTSIDE.
__________________
Save Classic!

Last edited by maximus_asinus; 09-14-2017 at 02:47 AM..
Reply With Quote
  #8  
Old 09-15-2017, 05:06 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
How does GuiScrollCtrl.scrollto(int, int) work? I am having issues with scrolling a GuiTextListCtrl inside of a GuiScrollCtrl. For whatever reason when using the arrow keys to navigate the menu the control won't scroll to the highlighted option / row. Scrolling with the mouse wheel is the only way to see further down the page.

Also can I catch if a player resizes GraalControl?
__________________
Save Classic!
Reply With Quote
  #9  
Old 09-15-2017, 05:49 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by maximus_asinus View Post
Also can I catch if a player resizes GraalControl?
PHP Code:
function GraalControl.onResize(widthheight) {

__________________
Reply With Quote
  #10  
Old 09-16-2017, 01:32 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I broke down and placed my script inside of a weapon NPC which has fixed a lot of the issues I was having before. Currently I am calling it in a level NPC like this:

PHP Code:
function onPlayerTouchsMe() {
  
temp.npc findweapon(WEAPON).FUNCTION(PARAMPARAM);

but I realize I could do something like

PHP Code:
function onPlayerTouchsMe() {
  
triggerClient("gui""WEAPON"PARAMPARAM);

I think I prefer the second method as it looks a lot cleaner, and believe it would function in the same way, but I'm wondering if one way is superior to the other, if there are any security flaws in either method, etc.

Quote:
Originally Posted by Crow View Post
PHP Code:
function GraalControl.onResize(widthheight) {

For whatever reason I assumed onResize was restricted to GUI Controls. Thanks, and thank you to everyone who has helped me out thus far.

Now I just need to understand this scrolling bug.
__________________
Save Classic!
Reply With Quote
  #11  
Old 09-16-2017, 09:45 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
okay to resolve the issue I used

PHP Code:
function GuiTextListCtrl.onSelect(entryid,entrytext,entryindex) {
  
GuiScrollCtrl.scrollto(0GuiTextListCtrl.getselectedrow() * FONTSIZE);

Probably not the most elegant solution but it is effective.
__________________
Save Classic!
Reply With Quote
  #12  
Old 09-17-2017, 01:35 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
I'm actually having more trouble with that hack workaround. Is there any way to find the position of a row and then scroll to it that way? To me it is pretty ridiculous that it doesn't automatically scroll to a selected row when the row is highlighted. It might be a byproduct of my script, but I really don't think so.
__________________
Save Classic!
Reply With Quote
  #13  
Old 09-18-2017, 03:50 AM
maximus_asinus maximus_asinus is offline
RIP DarkCloud_PK
Join Date: Oct 2001
Location: Canada
Posts: 3,743
maximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond reputemaximus_asinus has a reputation beyond repute
Can someone clarify the different between onKeyDown and keydown? I read somewhere that keydown works off the mapped keys in the options menu, and onKeyDown does not. If I wanted to allow the player to use mapped keys inside of a Gui would I have to use keydownglobal?
__________________
Save Classic!
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 06:06 AM.


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