Results 1 to 14 of 14
  1. #1
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Posts
    51

    Default Data Sharing between classes

    Was wondering if there was a way to share data between one class and another, both custom classes.

    Obviously writing to a file then reading from that same file could work. But is there a faster way? Maybe creating a static object somehow with static methods?

    Also whats a best way to get the locally controlled pawn reference.

  2. #2
    MSgt. Shooter Person
    Join Date
    Mar 2010
    Posts
    335

    Default

    Quote Originally Posted by beeph View Post
    Was wondering if there was a way to share data between one class and another, both custom classes.
    Obviously writing to a file then reading from that same file could work. But is there a faster way? Maybe creating a static object somehow with static methods?
    I may not have been understood you correctly, but sharing behavior exists already! It's not actually called sharing but you can overwrite/read any variable you want from where ever you want (Unless you have restrict access to it via modifiers like private or const or ...). Sharing is mostly used when you got multiple threads or mostly when you got multiple processes.

    Quote Originally Posted by beeph View Post
    Also whats a best way to get the locally controlled pawn reference.
    If you want to call it from an Actor class:
    getALocalPlayerController().pawn

    I hope it would help
    Last edited by a_karimi; 10-05-2010 at 11:08 PM.

  3. #3
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Location
    San Marcos, Texas
    Posts
    64

    Unhappy

    You can also use a "blackboard" approach. Say, for instance, that you want 4 pawns in a squad to share how many enemies they see.

    Create myBlackboard.uc with:

    Code:
    var int totalEnemiesSeen;
    
    function reportEnemies(int enemies)
    {
        totalEnemiesSeen += enemies;
    }
    Then make sure every member of the squad has access to this blackboard.

    Obviously this code isn't even nearly the best way to do that, but it should give you the idea.

  4. #4
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Posts
    51

    Default

    i like the blackboard.uc approach. The problem with writing directly to the world info is im at a menu screen and it seems that the world gets reinitialized when i enter the map level, and loses all the weapons/info i tried to pass to it. So I need something persistent. I will try this.

    also the local player controller is handy thank you.

    I assume i can isntantiate this class using the java method myBlackboard = new blackboard()? Then all the pawns can refence myBlackboard? Or does the engine automatically instantiate all your /Class/blah.u files on startup?

    I guess I'm a little confused on what class model utscript uses, unless it really is just straight javascript.
    Last edited by beeph; 10-06-2010 at 08:26 AM.

  5. #5
    Veteran
    Join Date
    May 2007
    Location
    Above KillZ, Below StallZ
    Posts
    9,953
    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

  6. #6
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Posts
    51

    Default

    Then make sure every member of the squad has access to this blackboard.

    Obviously this code isn't even nearly the best way to do that, but it should give you the idea.
    how do u make sure every pawn has access to the blackboard? That's kind of what i'm asking with data-sharing. The blackboard needs to be one instance, and global. I tried using a static function to access it, but it can only access default values says the compiler. I tried putting Default properties globalBlackboard = new Blackboard() in the class definition, but my static getGlobalBlackboard method still wont return that particular instance.

    If i spawn blackboards in all my pawns, then they each have their own instance of the blackboard, and arent sharing data.

    What i need is something like what class'WorldInfo'.static.getWorldInfo() does, but i looked at the implementation and it was native and undefined.

    I look at the UDK notes, and saw a flag that would allow a class to be global, but it says its broken cuz of 64 bits.

    Do you think I can just extend WorldInfo and add in my blackboard there?
    Last edited by beeph; 10-06-2010 at 04:02 PM.

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

    Default

    make an Info class, and keep track of it in your GameInfo
    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

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

    Default

    Quote Originally Posted by Blade[UG] View Post
    make an Info class, and keep track of it in your GameInfo
    ... and always put your defaultproperties at the BOTTOM of a class. And NEVER put the opening "{" in defaultproperties on the same line as the defaultproperties keyword
    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

  9. #9
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Posts
    51

    Default

    class charData extends Object;

    var int charDefaultWeapon;

    function static bool setDefaultWeapon ( int weaponID )
    {
    default.charDefaultWeapon= weaponID;
    return true;
    }

    function static int getDefaultWeapon ( )
    {
    return default.charDefaultWeapon;
    }

    DefaultProperties
    {
    charDefaultWeapon=0
    }

    Error, 'charDefaultWeapon': Can't change default values of non-config properties

    Failure - 1 error(s), 0 warning(s)

    I just dont think the 'static function/default variables' approach works. I will try loading my class in GameInfo but I'm at a menu screen, with no active game (hud disabled), and I'm trying to pass various options from a menu screen into the game instance. I'm not quite sure I can get a gameinfo reference from my gfxMoviePlayer class and even if i can, im worried that it will be destroyed once the real game begins.

  10. #10
    Iron Guard
    Join Date
    Dec 2009
    Location
    Ontario, Canada
    Posts
    632

    Default

    Code:
    function static bool setDefaultWeapon ( int weaponID )
    {
    default.charDefaultWeapon= weaponID;
    return true;
    }
    You cannot change a value in the class using a static call. Static can only read default values, because the item is assumed not to be instanced ( so read only, alter variables in another class ). If you want to alter/store values, you must spawn || New the class to an instance.
    Last edited by Wizzard~Of~Ozz; 10-07-2010 at 01:31 PM.
    Mike

  11. #11
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Location
    San Marcos, Texas
    Posts
    64

    Default

    Quote Originally Posted by Blade[UG] View Post
    make an Info class, and keep track of it in your GameInfo
    Okay, this is something I'm having issues with, and I think OP and I are asking the same question (as in a post I recently made).

    So I make an Info. How do I instantiate that within my GameInfo subclass so that some controllers can grab a reference to it?

    Is there some global location (per map? per game instance) where all classes are instantiated and registered?

    Or is it as simple as

    Code:
    class MyGameInfo extends GameInfo;
    
    var CustomClass myClass;
    
    event BeginPlay()
    {
        myClass = new CustomClass();
    }
    ?

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

    Default

    When you are calling something that is static, you are calling it IN the class, and not in an instance of the class. When operating static functions, you can only access default values of config variables. You will not likely use too many static functions in the course of your time using UnrealScript, because it is somewhat limiting in what you can do with it. The static function system does work fine, but is not at all the type of approach you would want to take here.

    Yes, your GameInfo will be destroyed when you open a new level, and a new GameInfo will be created. You could easily pass your options on the command line to your new map ( "open map?myvariable=whatever?myothervariable=somethinge lse") and parse them in your InitGame().

    FlowState:

    spawn() for a subclass of Info (which is an Actor), new() for an item that is not a subclass of Actor, only of Object.
    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

  13. #13
    MSgt. Shooter Person
    Join Date
    Sep 2010
    Location
    San Marcos, Texas
    Posts
    64

    Default

    So if one were not to take the static approach, and just create a normal class, then you could go ahead and code it similarly to what I have above?

    Also, probably worth a quick look into InitGame(), because understanding the flow of initialization is so important.

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

    Default

    yeah, create the instance on game startup, and keep track of it. InitGame(), I believe is called prior to the rest of the world initialization, and is mostly used in the default code to parse command line options for the game. PostBeginPlay() is called after the world is created, and such.
    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.