Results 1 to 6 of 6
  1. #1
    Skaarj
    Join Date
    Feb 2006
    Posts
    26

    Custom Class Problem

    I'm having trouble working with a new custom class I want to create. Basically the class doesn't need to extend anything important, I just want to use it to store data and eventually create an array of the objects of this class. Here is how I am doing it:

    Code:
    //===============================================
    // Setup custom class
    //===============================================
    class MyCustomClass extends Object;
    
    var string msg;                 // Just some temp string for testing
    
    defaultproperties
    {
    
    }
    Then, in my custom gametype class, I am trying to use it like this:

    Code:
    //===============================================
    // Setup new gametype
    //===============================================
    class MyGameType extends xDeathMatch;
    
    var MyCustomClass obj1;                  // Custom class object
    
    // Parse options for this game type
    event InitGame( string Options, out string Error )
    {
        Super.InitGame(Options, Error);
    
        obj1.msg = "THIS IS A TEST...............";
        Log($ obj1.msg);
    }
    
    defaultproperties
    {
    
    }[/
    When I check the log file, the msg from the custom gametype is not output. It doesn't seem to work. I just get errors saying Accessed None 'obj1' and Attempt to assign variable through None. What am I doing wrong here? Any pointers?

  2. #2
    Iron Guard
    Join Date
    Oct 2004
    Posts
    719

    Default

    obj1 doesnt equal anything if you dont create it

    put in obj1 = new class'MyCustomClass'; to set it or else it will return none

  3. #3

    Default

    Rather, put in:
    Code:
    obj1 = Spawn(class'MyCustomClass');
    That is, assuming the game can spawn things (extends Actor).

    The information you wish MyCustomClass to hold... does it need to change, or is it "static"?

  4. #4
    Iron Guard
    Join Date
    Oct 2004
    Posts
    719

    Default

    Actually his class extends object =x ^_^ =P

  5. #5
    MSgt. Shooter Person
    Join Date
    Dec 2005
    Posts
    328

    Default

    Any class needs to be spawned before you can use it in game.
    You can only access (Read Only) default properties of non-spawned classes.

    Spawn the class first, make it bHidden=True and you do what you like with.

  6. #6
    Skaarj
    Join Date
    Feb 2006
    Posts
    26

    Default

    Thanks guys, I just used the obj1 = new class'MyCustomClass'; in the InitGame() method an all works accordingly. I guess I didn't think it need to be initialized like that since it was already defined as a global variable. But I learned something new today. As always, you have all been a big help. Thanks again.


 

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.