Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Rar @ 1,000 onActions! (https://forums.graalonline.com/forums/showthread.php?t=65265)

xXziroXx 04-09-2006 02:00 AM

Rar @ 1,000 onActions!
 
Ok, im working on a Inventory but Ive encountered somewhat of a *problem*. Let me show you:


PHP Code:

... Some script ...

    new 
GuiScrollCtrl"InventoryScroll" ) {
      
height 149width 32 + (32 8)*10;
      
12175;
      
hscrollbar "dynamic";
      
vscrollbar "alwaysOff";
 
      for (
0clientr.Weapons.size(); ++) {
        
tokens clientr.Weapons[i].tokenize(";");
        new 
GuiBitmapButtonCtrl"InventoryButton" i) {
          
16 + (32 8)*i16;
          
width 32height 32;
          
mouseoverbitmap tokens[1];
          
normalbitmap tokens[1];
          
pressedbitmap tokens[1];
        }
      }
    } 


Is there another way to make it check if an icon is pressed rather then doing like this for each slot:

PHP Code:

//UGH!
function InventoryButton0.onAction()
{
  
player.chat "PRESSED 0!";
}

function 
InventoryButton1.onAction()
{
  
player.chat "PRESSED 1!";
}

function 
InventoryButton2.onAction()
{
  
player.chat "PRESSED 2!";
}

etcetc.. 


I just HATE alot of basicly exactly the same functions!

napo_p2p 04-09-2006 02:07 AM

Quote:

Originally Posted by xXziroXx
Is there another way to make it check if an icon is pressed rather then doing like this for each slot:

Yes. You can use 'catchevent'. - catchevent(obj, oldevent, newevent);

PHP Code:

new GuiBitmapButtonCtrl"InventoryButton" i) {
  
16 + (32 8)*i16;
  
width 32height 32;
  
mouseoverbitmap tokens[1];
  
normalbitmap tokens[1];
  
pressedbitmap tokens[1];

  
//added this line:
  
thiso.catchevent(this"onAction""onButtonPressed");


Now, every time a button is pressed, 'onButtonPressed' will be called (with a parameter that is a reference to the object that called it).

Example:
PHP Code:

function onButtonPressed(obj) {
  
player.chat temp.obj.name;



xXziroXx 04-09-2006 02:09 AM

Napo, I think I might love you! ;o

ApothiX 04-11-2006 02:45 PM

It might also be easier if you assign a variable to the object containing the number of the control.

For example:
PHP Code:

new GuiBitmapButtonCtrl"InventoryButton" i) { 
  
16 + (32 8)*i16
  
width 32height 32
  
mouseoverbitmap tokens[1]; 
  
normalbitmap tokens[1]; 
  
pressedbitmap tokens[1];

  
// ** Added
  
this.buttonnumber i;

  
thiso.catchevent(this"onAction""onButtonPressed"); 
}

// ** Modified
function onButtonPressed(obj) { 
  
player.chat "Button Number: " obj.buttonnumber " pressed!"




All times are GMT +2. The time now is 10:38 PM.

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