Announcement

Collapse
No announcement yet.

Custom Class Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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
    obj1 doesnt equal anything if you dont create it

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

    Comment


      #3
      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"?

      Comment


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

        Comment


          #5
          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.

          Comment


            #6
            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.

            Comment

            Working...
            X