Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-09-2006, 02:00 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
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
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!
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #2  
Old 04-09-2006, 02:07 AM
napo_p2p napo_p2p is offline
oh snaps
napo_p2p's Avatar
Join Date: Sep 2003
Location: Pismo Beach, California
Posts: 2,118
napo_p2p has a spectacular aura aboutnapo_p2p has a spectacular aura about
Send a message via AIM to napo_p2p Send a message via MSN to napo_p2p
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;

__________________
Scito hoc super omnia.
Haec vita est tua una sola.
Dum vita superest, utere maxime quoque puncto, momento, et hora quae habes.
Tempus neminem non manet.
Noli manere tempus.
Carpe Diem

Seize the Day.
Reply With Quote
  #3  
Old 04-09-2006, 02:09 AM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
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
Napo, I think I might love you! ;o
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #4  
Old 04-11-2006, 02:45 PM
ApothiX ApothiX is offline
Okiesmokie
Join Date: May 2004
Posts: 1,447
ApothiX is on a distinguished road
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!"

__________________


[06:24:19] * Parts: Skyld (i=silent@unaffiliated/skyld) ("Perhaps Okiesmokie did not realise that I like the boys. ")
Reply With Quote
Reply


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 10:52 PM.


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