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

Author Topic: RequestSpecByKey (Client)  (Read 1018 times)

cloudnine

  • General Accounts
  • *
  • Posts: 80
    • View Profile
    • Youtube
RequestSpecByKey (Client)
« on: Dec 11, 13, 12:05:14 PM »

When trying to read a spec on the client using RequestSpecByKey
my subject ends up being the specoracle and the data is an eventobject

not as this post shows data should be the spec and so should the subject?
https://community.heroengine.com/forums/index.php/topic,4279.msg23850.html#msg23850

I have
A method in Combatant Class with me being the E_PlayerCharacter
which is called when a replication field on the E_PlayerCharacter is updated
Code: [Select]
oracle as NodeRef of Class CombatEffectSpecOracle = $SPECORACLEUTILS.GetCombatEffectSpecOracle()
      println("requesting spec !!!!!!!!!!Oracle and key" +oracle + dd.SpecKey +"And the ME Node is" +me)
      //Two types of listeners
      //var listener = oracle.CreateScriptListener( SYSTEM.EXEC.THISSCRIPT, false )
      var listener = oracle.CreateNodeListener( me, false )
      oracle.addListener( listener )
      oracle.RequestSpecByKey(dd.SpecKey, listener)
In the Combatant Class I have these
Code: [Select]
shared function EventRaisedNotify(obsSubject as NodeRef of Class ObsSubject, listener as NodeRef of Class ObsListener, data as NodeRef )
  println("Combatant Event Raised Notify!!!!!!!!Subject:" +obsSubject +"Listener:" +listener +"Data:" +data)
 
obsSubject.removeListener( listener )
 
.

method isListenerInterested( data as NodeRef ) as Boolean
// Supports the idea that listeners may have specific interests
//
println("          Is the listener interested           !!!!!!!!!!!!!!!!!!!!!!!!!!!!")
  return true
.
method destroyListener()
 
.
method EventRaised( obs as NodeRef of Class ObsSubject, data as NodeRef )
  println("Event raised in Combatant class!!!ObsSubjectis:" +obs +"Data:" +data +"The ME Node is" +me)
datastring as String = data
 // Same as client CLI command 
//SendPersistedClientCLI( "qn " +data )
 
where obs is kindof CombatEffectSpecOracle
  println("Subject is a     CombatEffectSpecOracle     !")
  myfakeoracle as NodeRef of Class CombatEffectSpecOracle = $SPECORACLEUTILS.GetCombatEffectSpecOracle()
  var mydata = myfakeoracle.GetSpecByKey(1)
  //mydata as NodeRef of Class CombatEffectSpecOracle = myoracle.GetSpecByKey(1)
  println("My Data:" +mydata)
  println("My Fake Oracle   " +myfakeoracle)
  myfakespec as NodeRef = GetProtoType("CombatEffectSpecOracle")
  myfakespec = myfakeoracle.GetSpecByKey(1)
  println("My Fake Spec:" +myfakespec)
 
  worldAnchor as NodeRef of Class world_anchor = SYSTEM.INFO.WORLDANCHOR
  oracle as NodeRef of Class SpecOracle = worldAnchor.GetCombatEffectSpecOracle()
  fake2 as NodeRef of Class CombatEffectSpec= oracle.GetSpecByKey(1)
  println("Fake Spec 2   " +fake2 +"World Oracle" +oracle)
.

where obs is kindof CombatEffectSpec
  println("Subject is a     CombatEffectSpec     !")
.
where data is kindof  eventObject
  println("DATA is a  EVENTOBJECT   CombatEffectSpecOracle     !")
  if not (data is kindof CombatEffectSpec)
    GlomClass("CombatEffectSpec",data)
    println("Glommed a CombatEffectSpec Class onto DATA")
  .
.
And the Console Shows
Code: [Select]
11:42:26: SCRIPT:[CombatantClassMethods]:requesting spec !!!!!!!!!!Oracle and key10000051461And the me Node is9223372065196132748
11:42:26: SCRIPT:[CombatantClassMethods]:Event raised in Combatant Class!!!ObsSubjectis:1000005146Data:1000005150The me Node is9223372065196132748
11:42:26: SCRIPT:[CombatantClassMethods]:Subject is a     CombatEffectSpecOracle     !
11:42:26: SCRIPT:[CombatantClassMethods]:My Data:0
11:42:26: SCRIPT:[CombatantClassMethods]:My Fake Oracle   1000005151
11:42:26: SCRIPT:[CombatantClassMethods]:My Fake Spec:0
11:42:26: SCRIPT:[CombatantClassMethods]:Fake Spec 2   0World Oracle1000005154
11:42:26: SCRIPT:[CombatantClassMethods]:DATA is a  EVENTOBJECT   CombatEffectSpecOracle     !
11:42:26: SCRIPT:[CombatantClassMethods]:Glommed a CombatEffectSpec Class onto DATA
11:42:26: SCRIPT:[CombatantClassMethods]:The Data is a COMBATEFFECTSPEC           
11:42:26: SCRIPT:[CombatantClassMethods]:Combatant Event Raised Notify!!!!!!!!Subject:1000005146Listener:1000005147Data:1000005150
11:43:25: SCRIPT:[CombatantClassMethods]:COMBATANT REPLICATION FIELDUPDATED DisplayTracker!!!
11:43:25: SCRIPT:[CombatantClassMethods]:DiffForCombatEffects!!!!!
11:43:25: SCRIPT:[CombatantClassMethods]:found effectID:340
11:43:25: SCRIPT:[CombatantClassMethods]:total effect: 1
Any ideas?
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1407
    • View Profile
    • Forever Interactive, Inc.
Re: RequestSpecByKey (Client)
« Reply #1 on: Dec 11, 13, 02:12:32 PM »

The problem is this line:

oracle.addListener( listener )

When you add a listener to the oracle, then naturally the oracle is the subject.  But that is not what you want.  Inside of RequestSpecByKey(), it properly adds the listener to the spec and then that is the subject.

So remove the line shown above.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

cloudnine

  • General Accounts
  • *
  • Posts: 80
    • View Profile
    • Youtube
Re: RequestSpecByKey (Client)
« Reply #2 on: Dec 12, 13, 07:29:24 AM »

Ok it works now.

I had added the addlistener() part because the EventRaised was never getting called
turns out I had to use the world_anchor here
Code: [Select]
wa as NodeRef of Class world_anchor = SYSTEM.INFO.WORLDANCHOR
      oracle as NodeRef of Class CombatEffectSpecOracle = wa.GetCombatEffectSpecOracle()
     
     //oracle as NodeRef of Class CombatEffectSpecOracle = $SPECORACLEUTILS.GetCombatEffectSpecOracle()
     
      var listener = oracle.CreateNodeListener( me, false )
      oracle.RequestSpecByKey(dd.SpecKey, listener)
Logged