Results 1 to 9 of 9
  1. #1
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    562
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default Looking for a smarter way to assign a reference

    I'm creating a custom kismet node for dialogue boxes within my game. Logically, these nodes need to interact with my HUD class.

    The only method I know of to connect the Kismet node to my custom HUD is to use the iterator foreach allActors(class'MyCustomHUD', out)
    Right off the bat, I feel as if this is a terribly inefficient way to handle this; I feel as if there is a better method I am neglecting.
    Granted, there will be only one instance of the HUD, so it should actually work whether efficient or not.

    But I am also unsure about how to actually assign a consistent reference. The iterator is fine if I need it to only send one command or tweak one variable from the HUD, but it slows down the process if I have to do this more than once within my code. So I want the node class to have a set reference to the HUD. There are a couple issues I have with doing this.

    The first is I wonder when it is good time to assign that reference. Knowing when the HUD will exist is one matter to itself, but I have no idea when the Kismet node will "exist;" I don't know if I can just throw this into the postbeginplay or such function and expect it to work like an actor placed in the level. So I ask, what gets called in a Kismet node before it gets activated by an earlier node, and what of such functions are called when there is a HUD to find?

    The next thing I wonder is about the actual syntax I need to assign that variable. I need to declare a variable "Var MyHUD HUD;" to be referenced in the script, and likewise I need such a reference to use with the iterator. I wonder if I need two such variables, as it seems a little silly to create an identical variable just to copy to its clone. But even so, I wonder what the proper way to pass that reference on is. Do I just say "HUD = H" or is there a special way I pass reference variables?

    And after all that, I am running into a compile error that is keeping me from testing this stuff. I keep getting "Error, 'ForEach': An iterator expression is required" from this code:
    Code:
    function FindHUD()
    {
        local ZCHUD H;
    
        foreach AllActors( class 'ZCHUD', H )
        {
            HUD = H;
        }
    
    
    }
    ...which is really starting to tick me off. I've used foreach iterators before and I see nothing wrong with my syntax.
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  2. #2
    Palace Guard

    Join Date
    Jun 2007
    Location
    Christchurch
    Posts
    3,514

    Default

    AllActors is an Actor method. Kismet nodes are based from Objects.

    You could use the GetWorld() function to first get the WorldInfo, and then from the world info iterate over all local player controllers, grabbing the HUD from each one to do what you want.

  3. #3
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    562
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default

    I was about to say "I already checked and the HUD extends from Actor!" But I think you mean that since the nodes extend from object they don't inherit Allactors from foreach.

    There is nothing in the documentation about GetWorld; I would appreciate it if you could explain how it is supposed to work in this situation.
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  4. #4

    Default

    GetWorldInfo() returns a reference to the WorldInfo, which is an actor. Consequently it is possible to call AllActors on the WorldInfo, i.e. "foreach GetWorldInfo().AllActors(...)"
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
    <TNSe> nono
    <TNSe> its always funny to find code a week later you dont even remember writing
    <Pfhoenix> what's worse is when you have a Star Wars moment
    <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
    Note that your questions via PMs will be ignored if they actually belong in the forum.

  5. #5
    Palace Guard

    Join Date
    Jun 2007
    Location
    Christchurch
    Posts
    3,514

    Default

    I was about to say "I already checked and the HUD extends from Actor!"
    Yes, but it depends where you are calling the code from. And it's unlikely to be the HUD since you're looking for the HUD.

    GetWorldInfo() is just a function inside SequenceObject.uc or one of those classes; it returns an instance reference to WorldInfo ... which is an Actor.

  6. #6

    Default

    Oh, and if you're accessing WorldInfo anyway, you can also work towards the HUD by asking the WorldInfo for the local PlayerController and using its MyHud property.
    Wormbo's UT/UT2004/UT3 mods | PlanetJailbreak | Unreal Wiki | Liandri Archives

    <elmuerte> you shouldn't do all-nighters, it's a waste of time and effort
    <TNSe> nono
    <TNSe> its always funny to find code a week later you dont even remember writing
    <Pfhoenix> what's worse is when you have a Star Wars moment
    <Pfhoenix> "Luke! I am your code!" "No! Impossible! It can't be!"
    Note that your questions via PMs will be ignored if they actually belong in the forum.

  7. #7
    Banned
    Join Date
    Feb 2011
    Location
    BXL/Paris
    Posts
    2,169

    Default

    Code:
    if(GetWorldInfo().GetALocalPlayerController() != None)
    	HUD = GetWorldInfo().GetALocalPlayerController().myHUD
    or use Target:
    Code:
    if(PlayerController(GetController(Target)) != None)
    	HUD = PlayerController(GetController(Target)).myHUD
    No need iterate through AllActors...

  8. #8
    Iron Guard
    Join Date
    Sep 2008
    Location
    Utah or California
    Posts
    562
    Gamer IDs

    Gamertag: Marscaleb PSN ID: Marscaleb

    Default

    Quote Originally Posted by Wormbo View Post
    GetWorldInfo() returns a reference to the WorldInfo, which is an actor. Consequently it is possible to call AllActors on the WorldInfo, i.e. "foreach GetWorldInfo().AllActors(...)"

    Mind = blown.

    Thank you all for the help!

    I am still left to wonder though:
    For a Kismet node, when is the best place/time to assign the reference?
    Follow my progress at:
    http://marscaleb.com/
    Read my new webcomic: Mischief in Maytia
    http://maytiacomic.com/

  9. #9
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,953

    Default

    If there's any possibility that there might be more than one Local PlayerController, you can use GetWorldInfo().AllControllers()
    http://www.ericbla.de http://www.dungeondefenders.com http://en.wikipedia.org/wiki/Warm_Gun http://www.rekoil.com http://www.groundbranch.com

    - Please don't send me private messages asking programming questions, those would be better asked on the Programming forum here. Thanks


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.