HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.

Author Topic: Adding item to inventory container problem  (Read 1282 times)

GiovanniGiacomo

  • World Owners
  • ****
  • Posts: 3
    • View Profile
Adding item to inventory container problem
« on: Dec 20, 12, 08:56:30 PM »

Hello, good night.

I'm creating an inventory system and it was going very well until I needed to add an item to the inventory container. The problem is, despite my efforts I can't seem to sucessfully add an item to the inventory, my last try was very promising but I got an error which I don't quite understand.

Here's the script:
Code: [Select]
shared function HE_ProcessCommandInput( account as NodeRef, input as String )
// The Command Handler calls this shared function based on a mapping stored on the COMMANDHANDLER prototype
//   which maps a /command to a script to call
//
  args as List of String
  Tokenize( input, args )
 
  playerinput as String = SubString(input, 9, 50)
 
  Character as NodeRef of Class LOM_Character = $LomCharacter.GetCharacterNode()
  ItemSpecOracle as NodeRef of Class _ItemSpecOracle = $_ITEMSYSTEM._GetItemSpecOracle()
 
  println(playerinput)
  AddItem($_ItemSpec1.CreateFromSpec())
 
.

shared function HE_CommandUsage( account as NodeRef, input as String )
  // NOTE, this style is much more efficient on the client than doing a seperate Msg() for each line.
  // This is because only a single label gets created in chat, rather than one per line.
  msg as String = "/Additem Itemname$R"
  msg = msg + "Itemname - The name of the item$R"
  Msg( account, msg )
.

function Msg( account as NodeRef, msg as String )
  $CHAT.CHATPLAYER( account, "", msg )
.

function AddItem( item as NodeRef )
  Character as NodeRef of Class LOM_Character = $LomCharacter.GetCharacterNode()
  ItemContainer as NodeRef of Class _ItemContainer = Character._ItemContainer(1)
 
  println("Added")
  ItemContainer._AddItemToContainer(item)
.

And here's the error message:
Quote
Area: 9223372055609790087 Instance: 1
[Fantasy Lowlands] SCRIPT ERROR: In function QueryPrototypeScriptsWithFunction: Prototype not found ID=9223372056283651841
12/21/2012 02:42:30 UTC
Call trace:
  Script BaseSpecClassMethods line 226 me[id=9223372056283651841 class=_ItemSpec,_StackableItemSpecDecorator,_CategoryItemSpecDecorator,_ValueItemSpecDecorator,_AccountBoundItemSpecDecorator,_SharableItemSpecDecorator]
  Script _ItemSpecClassMethods line 17 me[9223372056283651841]
  Script AddItem line 14 me[9223372056283651835]
  Script commandHQ line 360 me[9223372056283651835]
  Script _CommandHandlerClassMethods line 147 me[9223372056283651835]
starting method/function _PROCESSCOMMAND
starting me[id=9223372056283651835 class=_CommandHandler]

If you guys could help me solve this puzzle, I would be very grateful.  ;)
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: Adding item to inventory container problem
« Reply #1 on: Dec 20, 12, 11:04:11 PM »

Here is how I did it (Temporary for testing):

In my <Game-specific_ItemSystem> class that was glommed onto the "$_ITEMSYSTEM" system node:
Code: (hsl) [Select]
//Request from client to create an Item from a spec using a SpecKey.
//Once the item is created, request to add it to an item container (Inventory)
untrusted method Request_CreateItemFromSpecKey(specKey as ID)
  createdItem as NodeRef of Class _Item = $_ITEMSYSTEM._CreateItemFromSpecKey(specKey)
  account as NodeRef of Class _PlayerAccount = SYSTEM.REMOTE.CLIENT
  char as NodeRef of Class RO_playerCharacter = account.GetMyChar()
  inventory as NodeRef of Class RO_ItemContainer = char._GetItemContainerByName("inventory")
  println("InventoryID: " + inventory)
  if inventory._CanAddItemToContainer(createdItem)
    success as Boolean = inventory._AddItemToContainer(createdItem)
    if success
      println("Successfully added an item to container:" + inventory._GetItemContainerName() + " ItemID:" + createdItem)
    else
      println("Failed to add an item to container:" + inventory._GetItemContainerName() + " ItemID:" + createdItem)

    .
  else
    println("Couldnt add the item to the container:" + inventory._GetItemContainerName() + " It must be full")
  .
 
.

In order for me to create, and add an item to my inventory container, I just call this from the client and supply a specKey

As for the error, It says that the prototype was not found.
Unfortunately, I can't help with that :(
« Last Edit: Dec 21, 12, 01:37:00 AM by Jrome90 »
Logged

GiovanniGiacomo

  • World Owners
  • ****
  • Posts: 3
    • View Profile
Re: Adding item to inventory container problem
« Reply #2 on: Dec 21, 12, 10:28:53 AM »

Well, after a day trying to fix the problem I finally did it. You're code was very helpful.
Thank you very much  :D
Logged