HeroEngine Support > Scripting & Programming

[Resolved] System areas and areas in general

(1/2) > >>

gregoberfield:
So I've been working on system areas as part of the pre-work to storing game-specific data for future analytics and I have a couple of questions.

in E_WorldClassMethods I've added my system area to the KeepUpList function (easy enough) but that function is only called when the world boots, correct?  So the fact that I have:


--- Code: ---KeepAreaUp( 9223372056366123504, 2 )   // Server Communication area
--- End code ---

Won't be called right now - can I call that via an admin command and it'll still work?  Also - I set my instance number to 2 - is that going to be a problem or is the recommendation to come up a high number range to use instead for system areas?

In E_AreaClassMethods I added:


--- Code: ---  if GetAreaNumber() == 9223372056366123504
    $WORLD._RegisterSystemArea(PLAYER)
    Debug("AreaSpinUp", "Server communication system area registered.")
  .
--- End code ---

to the HE_PostOnAreaLoad but I'm never getting my debug message.  The area number listed is the area ID of the system area I created.  I figured that would execute but it doesn't seem to be.

Also - about areas -- I see that E_AreaClassMethods is attached to $AREA to override methods -- is there a way to have area specific scripts attached?  Or do we have to do it all in off of $AREA and then have logic to check the area ID to run area-specific functions?

Specifically I'm trying to write code for my new system area - but there's no reason for that code to be attached to $AREA since its only going to be needed by the one area.  Can I MPAC code to the area ID?

HE-CHRISTOPHER:

--- Quote from: gregoberfield on Jul 09, 10, 10:21:35 AM ---in E_WorldClassMethods I've added my system area to the KeepUpList function (easy enough) but that function is only called when the world boots, correct?

--- End quote ---

Correct.



--- Quote from: gregoberfield on Jul 09, 10, 10:21:35 AM ---Can I call that via an admin command and it'll still work?

--- End quote ---

Yes.


--- Quote from: gregoberfield on Jul 09, 10, 10:21:35 AM ---I set my instance number to 2 - is that going to be a problem or is the recommendation to come up a high number range to use instead for system areas?
--- End quote ---

I generally recommend starting at 1 and go up for instances, that makes is much more predictable from code when working with system areas that utilize N play instances to balance load.


--- Quote from: gregoberfield on Jul 09, 10, 10:21:35 AM ---In E_AreaClassMethods I added:


--- Code: ---  if GetAreaNumber() == 9223372056366123504
    $WORLD._RegisterSystemArea(PLAYER)
    Debug("AreaSpinUp", "Server communication system area registered.")
  .
--- End code ---

to the HE_PostOnAreaLoad but I'm never getting my debug message.  The area number listed is the area ID of the system area I created.  I figured that would execute but it doesn't seem to be.

--- End quote ---

Did you subscribe to that channel of messaging?  I got the message as expected.

https://wiki.heroengine.com/wiki/Debug_System#Debug_System


--- Quote from: gregoberfield on Jul 09, 10, 10:21:35 AM ---Also - about areas -- I see that E_AreaClassMethods is attached to $AREA to override methods -- is there a way to have area specific scripts attached?  Or do we have to do it all in off of $AREA and then have logic to check the area ID to run area-specific functions?

Specifically I'm trying to write code for my new system area - but there's no reason for that code to be attached to $AREA since its only going to be needed by the one area.  Can I MPAC code to the area ID?

--- End quote ---

There are a couple of options:

* GLOM a class onto the Area Root Node (GetRootNode())
* Area roots have a field named "script" that stores a reference to a script in which you could call functions
Either way, you would need to modify E_AreaClassMethods to perform a call to either the script (if one is specified) or to a method on the area root node should it be implemented.


--- Code: ---  // object oriented method using dynamic composition (GLOMming)
  area_root_node as NodeRef of Class AreaRoot = GetRootNode()
  if HasMethod( area_root_node, "E_OnAreaSpinUp" )
    area_root_node.E_OnAreaSpinUp()
  .

--- End code ---


--- Code: ---  // functional method using a reference to a script
  area_root_node as NodeRef of Class AreaRoot = GetRootNode()
  if area_root_node.script != NONE
    area_root_node.script:MyFunctionAreaSpinUp()
  .

--- End code ---

gregoberfield:
Ok - so once an area is registered with the world server it will receive events.  What I'm trying to figure out (and digging through the HJ stuff now) is where/how to have the listeners tied to that area.

For example, I have an area "Server Communication" - do I just build a script ServerCommunicationClassMethods to handle the listener?  Do I put it into E_AreaClassMethods (or some other script I attach to the $AREA node)?

Basically, can you point me to the script file for, say the ChatSystem system area in HJ, or ShopSystem, or Auctions or something and I can probably back into the answers of all my other questions.

Thanks.
G

gregoberfield:
Still hoping for some direction on where to look in HJ for the system area code.  The areas are working now, and registering properly, but where do you GLOM the script code?  And how do you associate that code so it's attached to your system area?

Just point at a couple of examples in HJ and we can probably figure it out.

HE-CHRISTOPHER:

--- Quote from: gregoberfield on Jul 14, 10, 06:55:01 AM ---Still hoping for some direction on where to look in HJ for the system area code.  The areas are working now, and registering properly, but where do you GLOM the script code?  And how do you associate that code so it's attached to your system area?

Just point at a couple of examples in HJ and we can probably figure it out.

--- End quote ---

For Hero's Journey, they opted to handle the registration of the areas in the $AREA game specific override class HJAreaClassMethods during the HE_PostOnAreaLoad() call.  This has some advantages in centralizing the functionality in a well known location.

For your purposes, the equivalent would be implementing the code in E_AreaClassMethods (this is ok because this class and script are in the "game" package so you are free to make any modifications you desire).

I could argue either way that placing the functionality in the override for the $AREA system node vs GLOMming a class onto the area root node (GetRootNode()) and then modifying E_AreaClassMethods to call a shared function on the area root node during the area spinup process (HE_PostOnAreaLoad() would be an acceptable point).

If we want to GLOM a class on the area root node, why use a shared function?

I'm sure you are familiar with the classic diamond pattern in inheritance, HeroScript's solution is to the problem of ambiguous method calls is to simply not allow them.  Calling a method on the area root node it may not be ambiguous, however it would be really convenient if we could notify N GLOMmed classes on the area root node that the area has just spun up allowing each to do its thing.

Shared functions may be implemented in any number of classes that make up an object, because functions are explicitly called by <script>:<function> there is never any ambiguity allow us to notify every class that makes up an object that the area has just spun up.


--- Code: ---// in E_AreaClassMethods HE_PostOnAreaLoad()

// notify all of the classes making up the area root node that the area has just spun up
area_root_node as noderef of class AreaRoot = GetRootNode()
foreach s in QueryNodeScriptsWithFunction( area_root_node, "_AreaIsSpunUp" )
  s:_AreaIsSpunUp()
.

--- End code ---



--- Code: ---// in MyAreaRootNodeGLOMClassMethods
shared function _AreaIsSpunUp()
  // register me as a system area
  //   subscribe listeners
  // ETC
.

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version