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

Author Topic: [Resolved] How to find a previously created node in a new script?  (Read 185 times)

Bardaf01

  • General Accounts
  • *
  • Posts: 11
    • View Profile

Hello everybody!  :)

How could I find a previously created node in a new script/function (client-side only), please?

Here my script (client-side only):
Code: [Select]
public function makeGameMenu()
 
   // This creates a window GUIControl from a prototype.
  gamemenu as NodeRef of Class GUIControl = CreateNodeFromPrototype("JB_gameMenuPrototype")

  // Always make the new window renderable in the viewport first.
  gamemenu.build = true
.

Thanks a lot! ;D
Best regards.
« Last Edit: Jun 03, 17, 09:31:57 AM by Bardaf01 »
Logged

FI-ScottZ

  • General Accounts
  • *
  • Posts: 1380
    • View Profile
    • Forever Interactive, Inc.

I am not sure if I understand what you are asking.  Do you want to be able to reference that gamemenu node after this function ends?  If so, there are a few options, such as creating a field to reference that node and putting it on some class of a node that will store the reference.  Or another approach would be to define an association and add the association between your gamemenu node and another node.
Logged
Scott Zarnke
Lead Programmer, Visions of Zosimos
CTO, Forever Interactive, Inc.

Bardaf01

  • General Accounts
  • *
  • Posts: 11
    • View Profile
[Resolved] How to find a previously created node in a new script?
« Reply #2 on: Jun 03, 17, 09:30:25 AM »

Hello FI-ScottZ,

Thanks for your answer. Yes, that's what I meant. :)
Okay, I'm going to look for more information on these two solutions on the wiki.

Thank you very much! ;D
Cordially.
Logged

nocake

  • General Accounts
  • *
  • Posts: 390
    • View Profile
    • BlightMMO

There is a system node already for handling GUI's.

Be sure to use it!!

I believe the system node is called: $GUI

There are also layers to your GUI, be sure to add your newly created GUI to the right layer or make a new one.
Then later you can call to: FindGUIControlByName($GUI._findLayerByName("game"), "abilitybar")

http://wiki.heroengine.com/wiki/GUI_functions

Bardaf01

  • General Accounts
  • *
  • Posts: 11
    • View Profile

Hello nocake! :D

Ah... it's nice too! Thanks a lot! ;D

EDIT: here my "final" script now:
Code: [Select]
public function MakeMenu(layerName as String, prototypeName as String) as NodeRef of Class GUIControl
   
  // Store in this variable the return of the "CheckIfMenuExists" function.
  memorizeNodeRef as NodeRef of Class GUIControl = (CheckIfMenuExists(layerName, prototypeName))
 
  if(memorizeNodeRef == None)
   
    // This creates a GUIControl node from a prototype.
    menu as NodeRef of Class GUIControl = CreateNodeFromPrototype(prototypeName)
   
    // This modifies its layer.
    menu.layer = layerName

    // Always make the new node renderable in the viewport first.
    menu.build = true
   
    // Return the NodeRef freshly created.
    return menu
 
  else
    // destroy the node.
    DestroyNode(memorizeNodeRef)
   
    // Return "None" as the node has been destroyed.
    return None
  .
.
 
 
public function CheckIfMenuExists(layerName as String, prototypeName as String) as NodeRef
 
  // Find and catch the NodeRef in the "catchNodeRef" variable. The variable may be empty (0 as value) if this node doesn't exist...
  catchNodeRef as NodeRef of Class GUIControl = (FindGUIControlByName($GUI._findLayerByName(layerName), prototypeName))
 
  // If "menu" is not 0 (if this node exists), return "catchNodeRef".
  if catchNodeRef != 0
    return catchNodeRef
   
  // Otherwise, return "None".
  else
    return None
  .
.

Best regards.
« Last Edit: Jun 03, 17, 07:25:12 PM by Bardaf01 »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1072
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG

I use something similar. These 3 small functions are in most windows we have. Each has comments to help explain why they are used.

Code: [Select]

// separate from the toggle function, this can be used to make sure it is open

public function Start()
  var win = getInventoryWindowClass()                  // get our new window
  if win != None
    destroynode(win)                                   // if its made, remove old to keep from duplicates
  .
  win = CreateNodeFromPrototype( "InventoryWindow" )   // make it
  win.build = true
.

// can be used with key press to open and close

public function toggleInventoryWindow()

  var win = getInventoryWindowClass()
  if win == None
    Start()                   // build it

  else
    destroynode(win)       // remove it
  .
.

// this might be used in many areas, defined in one place
// by having its own class (instead of GUIControl), it can support variables (which can hold temp values)

function getInventoryWindowClass() as NodeRef of Class InventoryWindow

  return FindGuiControlByName(None, "game.InventoryWindow")
.

Logged
Heroes and Villains Lead programmer/scripter
Exile Online Lead programmer/scriptor

Bardaf01

  • General Accounts
  • *
  • Posts: 11
    • View Profile

Hello Thazager! :D

Thank you for this share! ;)

Cordially.
Logged