Announcement

Collapse
No announcement yet.

return class name

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

    return class name

    Hi,
    Learning UnrealScript and I wonder if there is a function that can return class name ? I need to check if certain element in array variable is holding an actor of certain class type.

    Thanks

    #2
    Usually something like this works

    Code:
    if(MyArray[i].class == class'SomeClass')
    {
      //Do Something
    }

    Comment


      #3
      Well, if i'm not mistaken, Class variable holds class itself. For example
      var Actor SomeActor;

      //................

      function class<Actor> GimmeClassName(Actor TargetActor)
      {
      return TargetActor.Class;
      }
      But don't be confused, it returns not class name (like string), but class itself.

      Comment


        #4
        Code:
        if (MyArray[i].IsA('SomeClass')) {
            // Do something
        }

        Comment


          #5
          Originally posted by 100GPing100 View Post
          Code:
          if (MyArray[i].IsA(class'SomeClass')) {
              // Do something
          }
          And this is the fastest way (if you are doing the check too often)

          Code:
          if (SomeClass(MyArray[i]) != none) {
             //Do something
          }

          Comment


            #6
            Originally posted by Saishy View Post
            And this is the fastest way (if you are doing the check too often)

            Code:
            if (SomeClass(MyArray[i]) != none) {
               //Do something
            }
            Yeah, totally forgot about that method (even though I only use that one).

            Comment


              #7
              Wonderful all the methods work.here are few things I noticed:

              - I had to use IsA without class like this:
              Code:
              if (MyArray[i].IsA('SomeClass')) {
                  // Do something
              }
              - The casting way return classname_x where x is the number of my spawned actor

              Many Thanks To All

              Comment


                #8
                test this for get name of a class:
                Code:
                object(class'SomeClassName').Name

                Comment


                  #9
                  Originally posted by Welliam View Post
                  - The casting way return classname_x where x is the number of my spawned actorl
                  Thats the instance name. To get the class from the instance use .class

                  Comment


                    #10
                    Originally posted by arashjfz View Post
                    test this for get name of a class:
                    Code:
                    object(class'SomeClassName').Name
                    Thanks but need to test against variable.


                    Originally posted by Spoof View Post
                    Thats the instance name. To get the class from the instance use .class
                    yes thanks

                    Comment


                      #11
                      If you need to check that something is a specific class, and that class only, you should use .class, otherwise type-cast it, unless you need to not create a dependency on that class, in which case use IsA. Normally if you need to use anything but the type-cast, though, you're probably going about some part of the whole transaction in a questionable fashion.

                      Comment


                        #12
                        @Blade[UG] yes I see. I can use all the methods described here..........thanks

                        Comment

                        Working...
                        X