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

Author Topic: [Resolved] GUI data to window - Help  (Read 3829 times)

DrunkSquirrel

  • World Owners
  • ****
  • Posts: 3
    • View Profile
[Resolved] GUI data to window - Help
« on: Sep 06, 12, 09:20:26 AM »

Hello, I am currently working on trying to make a test character stats window only for now containing the health and mana. So far I've been able to create the window but its not recognizing the updated event like E_Statusbar.

E_playerAccountClassMethods
Code: [Select]
CharWindow as NodeRef of Class GUIMovePanel = FindGUIControlByName(0, "CharWindow")
        if CharWindow != None
          DestroyNode( CharWindow )
        .
        CharWindow =  createNodeFromPrototype("CharWindow")
        CharWindow.build = true
        lbl as NodeRef of Class GUILabel = FindGUIControlByName(CharWindow, "book.health")
       
        $LightweightEvents.addLightweightEventListener(addedNode, "hpUpdated", CharWindow)

CharWindow
Code: [Select]
function Init()
   
newindow as NodeRef of Class GUIMovePanel = createNodeFromPrototype("CharWindow")
newindow.build = true
char as NodeRef of Class E_CommonCharacter

CharWindowClassMethods
Code: [Select]
method lightweightEventRaised(subject as ID, eventType as String, data as NodeRef)
  when eventType
    is "hpUpdated"
      char as NodeRef of Class E_CommonCharacter = subject
      if char != None
        me.SetHealthStat(char.E_hitPoints)

      .
    .
  .
.

method SetHealthStat(theHealth as String)
  newindow as NodeRef of Class GUIMovePanel = FindGUIControlByName(me, "CharWindow")
  lbl as NodeRef of Class GUILabel = FindGUIControlByName(newindow, "book.health")
  lbl.text = theHealth
.

The window is called but the data to the label does not change. Could someone could point me in the right direction as to what I'm doing wrong?
« Last Edit: Sep 10, 12, 06:04:24 PM by HE-Cooper »
Logged

PN-Dwight

  • General Accounts
  • *
  • Posts: 465
    • View Profile
    • Pirates' Nest
Re: GUI data to window - Help
« Reply #1 on: Sep 06, 12, 09:38:50 AM »

I remember something along the lines of:

health copies Integer (see it as a pointer). Check the original method again.

DrunkSquirrel

  • World Owners
  • ****
  • Posts: 3
    • View Profile
Re: GUI data to window - Help
« Reply #2 on: Sep 06, 12, 10:57:00 AM »

I remember something along the lines of:

health copies Integer (see it as a pointer). Check the original method again.

Yeah that is this:
Code: [Select]
method SetHP(hp copies Integer)
  if hp < 0
    hp = 0
  .
  healthSlider as NodeRef of Class GUIControl = FindGUIControlByName(me, "healthPanel.healthSlider")
  healthSlider.removeAnimations()
  var size = -1.0 * hp
  //1 field(string), the field on the GUIControl to such as size.x or defaultStatePresentation.color.a
  //2 min(float) (this is NOT the start value for the animation. That is the current value of the field to which you are applying the min/max values)
  //3 max(float)
  //4 duration in seconds(float)
  //5 repeat count(integer) (0=repeat infinitely, 1-n do animation that number of times)
  //6 reverse(boolean), forward and backward(true), or just forward(false)
  //7 curve(Enum of type interpolation curve), LINEAR, HOLD, EASE_IN, EASE_OUT, SMOOTH
  //8 restore(boolean), restores the orignal value after the animation is finished
  //9 delay in seconds(float), the amount of time to wait before actually starting the animation
  //10 id(string), the ID of the animation
  animationString as String = "size.x,"
  animationString = animationString + healthSlider.size.x + ","
  animationString = animationString + size +","
  animationString = animationString + .1 + ","
  animationString = animationString + 1 + ","
  animationString = animationString + "false,"
  animationString = animationString + "LINEAR," 
  animationString = animationString + "false,"
  animationString = animationString + "0,"
  animationString = animationString + "slide"
 
  GUIAnimation:addAnimation(healthSlider, "Interpolate", animationString)
.

But I'm only trying to get the integer "E_hitPoints" on a window other than E_statusbar.
Logged

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: GUI data to window - Help
« Reply #3 on: Sep 06, 12, 04:32:23 PM »

Code: (hsl) [Select]
method SetHealthStat(theHealth as String)
  newindow as NodeRef of Class GUIMovePanel = FindGUIControlByName(me, "CharWindow")
  lbl as NodeRef of Class GUILabel = FindGUIControlByName(newindow, "book.health")
  lbl.text = theHealth
.

is the guicontrol "book" a child of the "Charwindow"?

Assuming it is, then:

Code: (hsl) [Select]
method SetHealthStat(theHealth as integer)
  lbl as NodeRef of Class GUILabel= FindGUIControlByName(me,"book.health")
 
  lbl.text = theHealth
Should work
« Last Edit: Sep 06, 12, 04:36:03 PM by Jrome90 »
Logged

Arlohian

  • General Accounts
  • *
  • Posts: 43
    • View Profile
Re: GUI data to window - Help
« Reply #4 on: Sep 07, 12, 04:43:00 PM »

Ok, if i understand right, you want the text do update dynamicly? not just when you open the window.

As you tried, easiest way to do it is to use listeners.

All of this is client-side
1. You need to create the listener for the window, this could be done somewhere else, just need a noderef to the window instead of "me", i personaly dont like clutter from other smaller functions in any kind of main function.
Code: (hsl) [Select]
// This is in your charater window class methods script
method InitializeCharWindow()
  acct as NodeRef of Class E_playerAccount = GetAccountID()
  player as NodeRef of Class E_playerCharacter = acct.GetMyCharacter()

  $LightweightEvents.addLightweightEventListener(player, "hpUpdated", me)

  // here i would also manualy call all the functions that the listener pulls, to initial-set the labels
.

2. The method implementing what to do when the listener tells the window a node has been updated.

Code: (hsl) [Select]
// This is in your charater window class methods script
method lightweightEventRaised(subject as ID, eventType as String, data as NodeRef)
  char as NodeRef of Class E_playerCharacter = subject
  if char = None
    return
  .
 
  when eventType
    is "hpUpdated"
      me.Set_Hp(char)
    .
  .
.

Also keep in mind that if you destroy your char window the listeners get destroyed along with it.

Hope this helps!

EDIT...
« Last Edit: Sep 08, 12, 03:38:59 AM by Arlohian »
Logged
Fledgling programmer

Jrome90

  • General Accounts
  • *
  • Posts: 330
    • View Profile
Re: GUI data to window - Help
« Reply #5 on: Sep 07, 12, 07:50:56 PM »


All of this is client-side
1. You have to do is add a parent class ObsListener to your gui control window

You don't need ObsListener for the LightweightEvents
Logged

Arlohian

  • General Accounts
  • *
  • Posts: 43
    • View Profile
Re: GUI data to window - Help
« Reply #6 on: Sep 08, 12, 03:40:29 AM »

Seems like it now when i tried to remove it... When i was doing my character window a week ago maybe, it all started to work like magic when i added it. Guess it must have been some typo i fixed after that or something. Edited it out.
Logged
Fledgling programmer

DrunkSquirrel

  • World Owners
  • ****
  • Posts: 3
    • View Profile
Re: GUI data to window - Help
« Reply #7 on: Sep 08, 12, 12:23:23 PM »


All of this is client-side
1. You have to do is add a parent class ObsListener to your gui control window

You don't need ObsListener for the LightweightEvents

Okay so far I've found out 2 things.

1. The window is NOT listening to anything, it's not detecting the events when they are executed.

2. The method works fine like this:

Code: [Select]
method SetHealthStat()
  newindow as NodeRef of Class GUIMovePanel = FindGUIControlByName(me, "CharWindow")
  lbl as NodeRef of Class GUILabel = FindGUIControlByName(newindow, "book.health")
  chin as NodeRef of Class E_playerCharacter
  lbl.text = "lol"
.

But not like this:

Code: [Select]
method SetHealthStat()
  newindow as NodeRef of Class GUIMovePanel = FindGUIControlByName(me, "CharWindow")
  lbl as NodeRef of Class GUILabel = FindGUIControlByName(newindow, "book.health")
  chin as NodeRef of Class E_playerCharacter
  lbl.text = chin.E_hitPoints
.

When it is called this way, it spits this error out:
Code: [Select]
!ERROR!HeroScript::HeroMachine::ScriptError:GOM::getVariableReferenceFromNode (10757): requested node ID (0) not found
Logged

Arlohian

  • General Accounts
  • *
  • Posts: 43
    • View Profile
Re: GUI data to window - Help
« Reply #8 on: Sep 08, 12, 02:38:30 PM »

This i know for sure :)

Code: (hsl) [Select]
method SetHealthStat()
  newindow as NodeRef of Class GUIMovePanel = FindGUIControlByName(me, "CharWindow")
  lbl as NodeRef of Class GUILabel = FindGUIControlByName(newindow, "book.health")
  chin as NodeRef of Class E_playerCharacter
  lbl.text = chin.E_hitPoints
.

Will return a script error because you did not set chin to any value, it is a noderef of class E_PlayerCharacter, however doesn't specify which character (Meaning chin = 0).  The two functions below will find you the account that is used, then the character.

Code: (hsl) [Select]
acct as NodeRef of Class E_playerAccount = GetAccountID()
player as NodeRef of Class E_playerCharacter = acct.GetMyCharacter()

Sorry for the earlier confusion, you learn something every day :)
« Last Edit: Sep 08, 12, 02:41:20 PM by Arlohian »
Logged
Fledgling programmer