View Single Post
  #10  
Old 08-06-2011, 04:57 PM
Adddeeee Adddeeee is offline
Registered User
Join Date: Aug 2011
Posts: 30
Adddeeee is on a distinguished road
Hi!

This is what we've got so far. We have now updated the script so that our trigger action triggers onActionBuyItem.

Although, we have a variable called this.itemselected, which will store information regarding the currently selected item.

this.itemselected contains one of the two available gui controls: Shop_Item_Fireball or Shop_Item_Sword.

The gui looks just fine when running the script. We can click on the different items and the currently selected item changes.

Although, when we trigger the server via triggeraction, the gui control which is stored in this.itemselected disappears. We've noticed that this happens when we use this.itemselected as a parameter for triggeraction. If we use a string, for example "higuys" as parameter to the triggeraction everything works just fine.

I get a feeling that we're not ready to build a shop system!

PHP Code:
function onActionBuyItem(item)
{
  
player.chat = item;  
}

function 
onCreated() 
{
  
this.setShape(1, 32, 32);
}

//#CLIENTSIDE
function onPlayerTouchsMe()
{
  new 
GuiBitmapBorderCtrl("Shop_Window") 
  {
    
this.profile = GuiBitmapBorderProfile;
    
this.width = screenwidth / 2;
    
this.height = screenheight / 2;
    
this.x = screenwidth / 2 - this.width / 2;
    
this.y = screenheight / 2 - this.height / 2;
    
this.canmove = false;
    
this.canresize = false;
    
this.makefirstresponder(true);
    
    new 
GuiButtonCtrl("Shop_Button")
    {
      
width = 100;
      
height = 40;
      
x = Shop_Window.width / 2 - this.width / 2;    
      
y = Shop_Window.height - this.height - 10;
      
text = "Buy";
    }
        
    new 
GuiShowImgCtrl("Shop_Item_Fireball") 
    {
      
x = 20;
      
y = 20;
      
width = 60;
      
height = 60;
      
      
this.imageselected = "split_fireball_selected.png";
      
this.imagenotselected = "split_fireball.png";
      
this.image = this.imageselected;
      
      
this.price = 20;
    }
    
    new 
GuiShowImgCtrl("Shop_Item_Sword") 
    {
      
x = Shop_Item_FireBall.x + Shop_Item_Fireball.width + 20;
      
y = 20;
      
width = 60;
      
height = 60;
      
      
this.imageselected = "split_sword_selected.png";
      
this.imagenotselected = "split_sword.png";
      
this.image = this.imagenotselected;
      
      
this.price = 30;
    }
  }
  
Shop_Window.show();
  
this.listofitems = {Shop_Item_Fireball, Shop_Item_Sword};
  
this.itemselected = this.listofitems[0];
}

function 
onMouseDown()
{
  if(!((
mousescreenx in |Shop_Window.x, Shop_Window.x + Shop_Window.width|)
      &&(
mousescreeny in |Shop_Window.y, Shop_Window.y + Shop_Window.height|)))
  {
    
Shop_Window.hide();
  }
}

function 
Shop_Button.onMouseDown()
{
  
triggeraction(this.x + 0.5, this.y + 0.5, "BuyItem", this.itemselected);
  
}

function 
Shop_Item_Fireball.onMouseDown()
{
  
temp.s = this.listofitems.size();
  
  for(
i = 0; i < temp.s; i ++)
  {
    
this.listofitems[i].image = this.listofitems[i].imagenotselected;   
    if(
this.listofitems[i] == Shop_Item_Fireball)
      
this.itemselected = this.listofitems[i];
  } 
  
Shop_Item_Fireball.image = Shop_Item_Fireball.imageselected;
}

function 
Shop_Item_Sword.onMouseDown()
{
  
temp.s = this.listofitems.size();
  
  for(
i = 0; i < this.listofitems.size(); i ++)
  {
    
this.listofitems[i].image = this.listofitems[i].imagenotselected;   
    if(
this.listofitems[i] == Shop_Item_Sword)
      
this.itemselected = this.listofitems[i];
  }
  
Shop_Item_Sword.image = Shop_Item_Sword.imageselected;
} 
Reply With Quote