View Single Post
  #13  
Old 08-06-2011, 07:00 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You can cut down on your 'itemSelected' code with catchevent. I.e:

PHP Code:
new GuiShowImgCtrl("Shop_Item_Fireball") {
  
// existing code...
  
thiso.catchevent(this.name"onMouseDown""onItemSelected");
}

// other code...

// The first parameter passed from a 'caught event' is the object that received it.
function onItemSelected(selected) {
  
// Loop through Items
  
for (temp.itemthis.listofitems) {
    
// Change Image 
    
temp.item.image = (temp.item == selected temp.item.imageselected temp.item.imagenotselected);
  }
  
// Set Selected to Item's Name (w/o the Shop_Item_ part)
  
this.itemselected selected.name.substring("Shop_Item_".length());

I also used the ternary operator, which is just: value = (condition ? true_result : false_result);

It would also fix your problem where you're passing an object to the server-side instead of string.

Objects behave weirdly (as you can see) resulting in their name getting passed or it passes null/0.
__________________
Quote:
Reply With Quote