GetDefaultByType

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


static readonly<Actor> GetDefaultByType(class<Actor> type)

Use this to find the default property of a class, rather than those of any particular actor.

Note that this is sensitive to whether the caller has a backpack, so it is not necessary to specifically check for a backpack and backpackmaxamount - checking maxamount will cover both situations.

Class example
{
    static void getImpRadius() {
        class<Actor> cls = "DoomImp";
        int impRadius = Actor(GetDefaultByType(cls)).Radius;
        console.printf("Imp default radius is: %d", impRadius);
    }
}

Custom property defaults can also be retrieved by using the name of the variable that the property refers to. This class retrieves the custom DropCategory property of the class that represents a treasure dropped by a monster:

class MonsterDrop : Inventory {
   String myCategory;
   
   property DropCategory: myCategory;
   default {
       MonsterDrop.DropCategory "Jewellery";
   }
}
Class example
{
    static void getMonsterDropCategory(String dropClass) {
        class<Actor> cls = dropClass;
        String dropCategory = MonsterDrop(GetDefaultByType(cls)).myCategory;
        console.printf("Drop category for %s is: %d", dropClass, dropCategory);
    }
}