Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   catchevent parameters? (https://forums.graalonline.com/forums/showthread.php?t=134265737)

scriptless 02-11-2012 10:37 AM

catchevent parameters?
 
So I am trying to pass a variable with an event.. Not sure if it's possible? Or if I am way wrong on how to do it? I am planning to have let's say 10 images, and clicking on them will make the player chat the number of the image it clicked on..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  for ( 
010i++ ) {
    new 
GuiShowImgCtrl("test" i) {
      
55;
      
50 40;
      
image "block.png";
      
thiso.catchevent(this"onMouseDown""onSelect"i); 
    }
  }
}
function 
onSelect() {
  
player.chat "a" SPC params[0];


Didn't work.

Removing i from catchevent(), however, shows the name of the Control.

ffcmike 02-11-2012 11:21 AM

Quote:

Originally Posted by scriptless (Post 1684247)
So I am trying to pass a variable with an event.. Not sure if it's possible? Or if I am way wrong on how to do it? I am planning to have let's say 10 images, and clicking on them will make the player chat the number of the image it clicked on..

PHP Code:

//#CLIENTSIDE
function onCreated() {
  for ( 
010i++ ) {
    new 
GuiShowImgCtrl("test" i) {
      
55;
      
50 40;
      
image "block.png";
      
thiso.catchevent(this"onMouseDown""onSelect"i); 
    }
  }
}
function 
onSelect() {
  
player.chat "a" SPC params[0];


Didn't work.

Removing i from catchevent(), however, shows the name of the Control.

The parameter received is actually the GUI object rather than its name. You can just write this. variables to the GUI object itself then use the object as reference:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  for ( 
010i++ ) {
    new 
GuiShowImgCtrl("test" i) {
      
55;
      
50 40;
      
image "block.png";
      
this.num i;
      
thiso.catchevent(this"onMouseDown""onSelect"i); 
    }
  }
}
function 
onSelect(temp.gui) {
  
player.chat temp.gui.num;



0PiX0 02-11-2012 07:39 PM

There is no fourth parameter for catchevent.

Admins 02-11-2012 08:08 PM

Do as ffcmike said. You cannot pass additional parameters to catchevent(). The first parameter in the catching function is always the object itself, and then follow the normal event parameters.
Remember additional values as this.variables in the GUI object itself.

scriptless 02-11-2012 08:31 PM

Quote:

Originally Posted by Stefan (Post 1684262)
Do as ffcmike said. You cannot pass additional parameters to catchevent(). The first parameter in the catching function is always the object itself, and then follow the normal event parameters.
Remember additional values as this.variables in the GUI object itself.

Thanks, that clear's things up for me :)

devilsknite1 02-19-2013 04:29 AM

Sorry for bumping this (it has been a year :(), but I've been attempting this method to no avail.
I've attempted even Thor's simple example; any other ways to do this? Or am I just doing something incorrectly?

EDIT: FIXED! Thanks to Hoyt1134
In case anyone else has this problem, here's a possible solution based off of ffcmike's example. I instead wanted to send the image of the selected weapon, so I will replace it with what I wanted to do with it:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.images = {};
  for ( 
temp.0temp.player.weapons.size(); temp.++ ) {
    
thiso.images.addplayer.weaponstemp.].image );
    new 
GuiShowImgCtrl"test" temp.) {
      
55;
      
50 temp.40;
      
image player.weaponstemp.].image;
      
thiso.catchEventthis.name"onMouseDown""onSelect" );
    }
  }
}
function 
onSelecttemp.gui ) {
  
temp.gui temp.gui.substring);
  
temp.image this.imagestemp.gui ];
  
player.chat temp.image;


Again, sorry for the bump, but this may be useful for others as catchEvent() does not include parameters... Maybe a useful addition?


All times are GMT +2. The time now is 12:04 PM.

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