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

Author Topic: _Item vs _ItemSpec on Client  (Read 1965 times)

brainache

  • World Owner
  • ****
  • Posts: 121
    • View Profile
_Item vs _ItemSpec on Client
« on: Jan 28, 13, 09:49:20 PM »

Confused as to how I can get details from the Server ItemSpec and link it to the instance of the object that has that spec...

ie:

When I open my inventory gui.. I can loop through all the items in the players container...
I can call requestItemEqup etc on those items and they work...

Now.. If I wanted to create an icon for that item.. with the itemname from the spec as its label.. I'm getting lost...

I do this:

        spec as NodeRef of Class _ItemSpecOracle = item.getMySpecOracle()
        spec.requestSpecByKey(item.SpecKey, spec.createNodeListener(me, false))


which calls

method EventRaised( obs as NodeRef of Class ObsSubject, data as NodeRef )

where I can do:
  spec as NodeRef of Class _ItemSpec = data

and get the _ItemName... ( or icon to show.. or whatever I set in the spec )...

but... I have no idea what _Item it was that it came from...


Am I approaching this incorrectly?  Or am I overlooking something?

Any help would be greatly appreciated!



Logged

TGSRofar

  • General Accounts
  • *
  • Posts: 153
    • View Profile
Re: _Item vs _ItemSpec on Client
« Reply #1 on: Jan 29, 13, 04:32:52 PM »

You shouldn't need to request the item spec if you are using the new built in item system.  When the items replicate to the client, the spec is requested and a reference is kept in the item class.  So you can do something like...
Code: [Select]
itemSpec as NodeRef of Class _ItemSpec = item._specRefNot sure if that helps you are not.
Logged
Ron Farrell
Lead Programmer
Triad Game Studios

brainache

  • World Owner
  • ****
  • Posts: 121
    • View Profile
Re: _Item vs _ItemSpec on Client
« Reply #2 on: Jan 29, 13, 06:42:33 PM »

You, sir... Have made my day!

I knew it had to be something that I overlooked... and that was exactly what I was missing...

thank you very much!

Logged

brainache

  • World Owner
  • ****
  • Posts: 121
    • View Profile
Re: _Item vs _ItemSpec on Client
« Reply #3 on: Jan 29, 13, 10:20:14 PM »

So... this.. in the documentation.. is incorrect?

Get a Spec on the Client
Assuming the spec oracle is set up to write out its specs as files to the repository, the client has access to that data using the client-side spec oracle.

Retrieving a spec on the client is a bit more complicated because the process is asynchronous. This requires you provide a listener to the oracle when you request the spec by its key, which will some time later produce a callback.

  var listener = oracle.createScriptListener( CallbackScript, false )
  // optionally you could create a nodeListener using the oracle.createNodeListener( nodeToNOtifyID, false)
  // A node listener gets a callback in all of its class method scripts in a shared function
  oracle.RequestSpecByKey( key, listener )
Logged

katoomm0m0

  • General Accounts
  • *
  • Posts: 44
    • View Profile
Re: _Item vs _ItemSpec on Client
« Reply #4 on: Jan 30, 13, 01:41:30 AM »

No, it is correct. In the case of the new item system framework, when the items arrive on the client due to being replicated, they request their spec themselves, and when the spec is loaded async. they set their specRef to the spec, that is why you in this case don't have to do it your self.

My advise to you would be to get familiar with how to do load on demand on the specs because you are going to need it a lot.
Logged
- Claus

brainache

  • World Owner
  • ****
  • Posts: 121
    • View Profile
Re: _Item vs _ItemSpec on Client
« Reply #5 on: Jan 30, 13, 05:45:20 AM »

Allrighty.. makes sense... so... then back to my original question...

Fro the method EventRaised( obs as NodeRef of Class ObsSubject, data as NodeRef ) method.. how do I link the received spec back to the item it came from?

Is thee something in the spec or obs data that I'm overlooking?  ( strangely, the "obs" and "data" node appear to the be the same  )
Logged

brainache

  • World Owner
  • ****
  • Posts: 121
    • View Profile
Re: _Item vs _ItemSpec on Client
« Reply #6 on: Jan 30, 13, 06:10:51 AM »

Ok.. I think I grok this now thanks to your mention of the new Item System setting its own _specRef...   I was calling requestSpecByKey from my inventory gui, not from my item class...    and that appears to be a dead-wrong approach as there isnt a link between the item and the spec at that point...   

That does make me wonder how I'll know when I have the specs loaded for inventory display.. but.. i'll look into that as I go along
Logged

Tarra2012

  • General Accounts
  • *
  • Posts: 113
    • View Profile
Re: _Item vs _ItemSpec on Client
« Reply #7 on: Feb 06, 13, 05:28:29 AM »

I had a similar issue when trying to get all data (mutable/immutable) together.
My solution was to send a parameter to the callback method.

The only way i found was to glom a class to one of the nodes that are used in listener/observer creation.

Am not using this approach anymore, but i know it worked.


Logged