View Single Post
  #20  
Old 12-10-2013, 05:38 PM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 353
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
i can see two big problems

you have the onSelect function wrapped within the gui container, it should be outside of the onCreated function with the gui name before the event name

you still arent comparing variables properly, it should be '==', just one '=' is for assigning variables

a better way to accomplish this would be to have an array of item data, and loop through the array when building the list,
the onSelect() function already returns the index of the list item you click, which can then be used to reference the price within the array

Graal Script Code:
//#CLIENTSIDE
function onCreated(){
  
//setup item data, {name, price}
  
this.items = {
    {
"Red Sword"100},
    {
"Flintlock Pistol"500}
  };

  
//loop through item array to build list
  
clearrows();
  for(
temp.thiso.items){
     
addrow(temp.ntemp.i[0]);
    
temp.++;
  }
  
//invoke the select action on the default row
  
setselectedrow(0);

}

//select event has list index parameter, use this to obtain price from array
function Items.onSelect(temp.i){
  
Price.text this.items[temp.i][1];

it is also worth mentioning that the parameter when building a new gui should not be passed as a string even though it would still work, its best to remove the " " quotes

you will also want to avoid using such a script within level npcs if theres going to be more than one shop, because they would conflict with eachother even if they are in a different level

the best method is to put gui scripts in a weapon, and then call a public function from the level npc script to the weapon script in order to invoke the display, and pass a parameter to identify the npc which called it
__________________
This signature has been deleted by Darlene159.

Last edited by Jakov_the_Jakovasaur; 12-10-2013 at 07:22 PM..
Reply With Quote