Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-06-2011, 12:46 AM
Sp_lit Sp_lit is offline
Mercury
Sp_lit's Avatar
Join Date: Mar 2010
Location: Sweden
Posts: 102
Sp_lit will become famous soon enough
Problem using a level NPC that's joined to a class

Hey there!
This is me and my friend's first attempt at GS2. This is what we've got so far. We're just wondering; are we on the right track here? We have encountered some problem with triggeraction when trying to trigger serverside from clientside, in a level NPC.

Any ideas or suggestions on what to improve or totally change?
In case the aweful script does not tell; we're trying to create a shop system..or something closely remote to one...

Help is very much appreciated, thanks!

Class:
Graal Script Code:
function onActionBuyItem()
{
  
player.rupees 0;
}

function 
onCreated() {
  
this.setShape(13232);
  
this.dontblock();
}

//#CLIENTSIDE
function onPlayerTouchsMe()
{
  new 
GuiBitmapBorderCtrl("Shop_Window"
  {
    
this.profile GuiBitmapBorderProfile;
    
this.width screenwidth 2;
    
this.height screenheight 2;
    
this.screenwidth this.width 2;
    
this.screenheight this.height 2;
    
this.canmove false;
    
this.canresize false;
    
this.makefirstresponder(true);
    
    new 
GuiButtonCtrl("Shop_Button")
    {
      
width 100;
      
height 40;
      
Shop_Window.width this.width 2;    
      
Shop_Window.height this.height 10;
      
text "Buy";
    }
        
    new 
GuiShowImgCtrl("Shop_Item_Fireball"
    {
      
20;
      
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"
    {
      
Shop_Item_FireBall.Shop_Item_Fireball.width 20;
      
20;
      
width 60;
      
height 60;
      
      
this.imageselected "split_sword_selected.png";
      
this.imagenotselected "split_sword.png";
      
this.image this.imagenotselected;
      
      
this.price 30;
    }
  }  
  
this.listofitems = {Shop_Item_FireballShop_Item_Sword};
  
this.itemselected this.listofitems[0];
}

function 
onMouseDown()
{
  if(!((
mousescreenx in |Shop_Window.xShop_Window.Shop_Window.width|)
      &&(
mousescreeny in |Shop_Window.yShop_Window.Shop_Window.height|)))
  {
    
Shop_Window.destroy();
  }
}

function 
Shop_Button.onMouseDown()
{
  
triggeraction(this.0.5this.0.5"ButItem"null);
}

function 
Shop_Button.onMouseUp()
{
  
Shop_Window.makefirstresponder(true);
}

function 
Shop_Item_Fireball.onMouseDown()
{
  for(
0this.listofitems.size(); ++)
  {
    
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()
{
  for(
0this.listofitems.size(); ++)
  {
    
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;

NPC:
Graal Script Code:
this.join("shopkeeper"); 
__________________
Reply With Quote
  #2  
Old 08-06-2011, 12:48 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike Send a message via Skype™ to ffcmike
Quote:
Originally Posted by Sp_lit View Post
triggeraction(this.x + 0.5, this.y + 0.5, "ButItem", null);
Looks like a mere typo.
Reply With Quote
  #3  
Old 08-06-2011, 01:03 AM
Sp_lit Sp_lit is offline
Mercury
Sp_lit's Avatar
Join Date: Mar 2010
Location: Sweden
Posts: 102
Sp_lit will become famous soon enough
Quote:
Originally Posted by ffcmike View Post
Looks like a mere typo.
Oh well..took you two minutes, took us four hours..

Just wondering; what do you think about the structure of our shop system? Any thoughts or suggestions?
__________________
Reply With Quote
  #4  
Old 08-06-2011, 01:05 AM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of light
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Box formatting is the devil.
__________________
Reply With Quote
  #5  
Old 08-06-2011, 01:10 AM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike Send a message via Skype™ to ffcmike
Quote:
Originally Posted by Sp_lit View Post
Graal Script Code:
  for(0this.listofitems.size(); ++) 
This is being a little bit picky and won't really make any difference in this particular instance but it's more efficient to avoid using .size(); within an array that doesn't change value in this type of loop.

With this type of loop where you're accessing 'i' it would take less script time to do:

Graal Script Code:
temp.this.listofitems.size();
for(
0temp.s++) 
This is albeit something that would be worthwhile when it comes to looping through much larger arrays, the reason being is that the .size(); function would be processed on every part of the loop, which takes longer with larger arrays.
Reply With Quote
  #6  
Old 08-06-2011, 01:34 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
You forgot temp.s on your is.
Reply With Quote
  #7  
Old 08-06-2011, 04:46 PM
Sp_lit Sp_lit is offline
Mercury
Sp_lit's Avatar
Join Date: Mar 2010
Location: Sweden
Posts: 102
Sp_lit will become famous soon enough
Quote:
Originally Posted by ff7chocoboknight View Post
Box formatting is the devil.
I bet it is, since I barely understand what it means..haha

Could you please expand or elaborate a bit on the meaning of Box formatting?

I suppose our structure is not that good?

And thanks for all the replies and comments so far!
__________________
Reply With Quote
  #8  
Old 08-06-2011, 04:57 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of lightff7chocoboknight is a glorious beacon of light
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Graal Script Code:
function Box()
{
  
this.herp "derp";
}

function 
notBox() {
  
this.hurr "durr";

__________________
Reply With Quote
  #9  
Old 08-06-2011, 05:04 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
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
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Box formatting is the ugliest thing to read through ever, not to mention how it expands the code for no good reason.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #10  
Old 08-06-2011, 05: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!

Graal Script Code:
function onActionBuyItem(item)
{
  
player.chat item;  
}

function 
onCreated() 
{
  
this.setShape(13232);
}

//#CLIENTSIDE
function onPlayerTouchsMe()
{
  new 
GuiBitmapBorderCtrl("Shop_Window"
  {
    
this.profile GuiBitmapBorderProfile;
    
this.width screenwidth 2;
    
this.height screenheight 2;
    
this.screenwidth this.width 2;
    
this.screenheight this.height 2;
    
this.canmove false;
    
this.canresize false;
    
this.makefirstresponder(true);
    
    new 
GuiButtonCtrl("Shop_Button")
    {
      
width 100;
      
height 40;
      
Shop_Window.width this.width 2;    
      
Shop_Window.height this.height 10;
      
text "Buy";
    }
        
    new 
GuiShowImgCtrl("Shop_Item_Fireball"
    {
      
20;
      
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"
    {
      
Shop_Item_FireBall.Shop_Item_Fireball.width 20;
      
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_FireballShop_Item_Sword};
  
this.itemselected this.listofitems[0];
}

function 
onMouseDown()
{
  if(!((
mousescreenx in |Shop_Window.xShop_Window.Shop_Window.width|)
      &&(
mousescreeny in |Shop_Window.yShop_Window.Shop_Window.height|)))
  {
    
Shop_Window.hide();
  }
}

function 
Shop_Button.onMouseDown()
{
  
triggeraction(this.0.5this.0.5"BuyItem"this.itemselected);
  
}

function 
Shop_Item_Fireball.onMouseDown()
{
  
temp.this.listofitems.size();
  
  for(
0temp.s++)
  {
    
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.this.listofitems.size();
  
  for(
0this.listofitems.size(); ++)
  {
    
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
  #11  
Old 08-06-2011, 06:31 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
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
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
If I understand it correctly, this.itemselected is a GUI control, yeah? GUI controls are a clientsided object and thus can't be read on serverside.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #12  
Old 08-06-2011, 06:35 PM
Adddeeee Adddeeee is offline
Registered User
Join Date: Aug 2011
Posts: 30
Adddeeee is on a distinguished road
Yepp. Since this.itemselected contains a gui control. But when I add one more parameter to the triggeraction it works just fine.

triggeraction(this.x + 0.5, this.y + 0.5, "BuyItem", this.itemselected, null);

Any thoughts regarding that?
Reply With Quote
  #13  
Old 08-06-2011, 08: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:

Graal Script 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
  #14  
Old 08-06-2011, 08:12 PM
Adddeeee Adddeeee is offline
Registered User
Join Date: Aug 2011
Posts: 30
Adddeeee is on a distinguished road
Thank you very much!

I was a little bit concerned about how to solve that problem.

I'm also a little bit concerned about where to put the raw data.

I would like to create an array consisting of arrays to keep track of all the items:

//{Gui name, name, price}
this.shop_item_fireball = {"Shop_Item_Fireball", "Fireball", 30};

and then create an array called

this.listofItems = {this.shop_item_fireball};

When this is done on the server side I would like to pass that information to the clientside so that the GUI can be built.

Would that be inefficient? Or what do you think?
Reply With Quote
  #15  
Old 08-06-2011, 08:55 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
Your best bet would be to do something like this:

Graal Script Code:
function onCreated() {
  
this.items = {
    {
"Item Name""Description""Price"}
  };
  
this.join("shopkeeper");
}

//#CLIENTSIDE

function onCreated() {
  
this.items = {
    {
"Item Name""Description""Price"}
  };  

It's not very DRY, but transferring data from the server-side to the client-side in a level npc can be a un-needed pain in the ass. It'll be more instant this way anyway.

Then in your shopkeeper class just process the this.items array and create the list you need. Also on the server-side verify their purchase against the server-side items array.
__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 09:02 PM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright (C) 1998-2008 Linux cyberjoueurs All Rights Reserved.