There are errors because Armor and Inventory are not properties of Thing (and you are trying to use them like properties, with "."). They are names of derived classes. You may want to read about inheritance concept.
Then, Amount and SaveAmount are properties of classes of Inventory and BasicArmorPickup, respectively. To access those properties you need to cast Thing to derived classes, like this:
Ошибки из-за того что Armor и Inventory - не свойства класса Thing, а имена унаследованных классов (а код пытается обратиться к ним как к свойствам, через точку "."). Может быть полезно почитать про наследование.
Далее, Amount и SaveAmount - свойства классов Inventory и BasicArmorPickup, соответственно. Чтобы получить доступ к этим свойствам, нужно сначала преобразовать Thing к унаследованному классу, вот так:
Code: Select all
if (e.thing is "BasicArmorPickup")
{
BasicArmorPickup i = BasicArmorPickup(e.thing);
Console.Printf("Found armor, amount: %d", i.SaveAmount);
}
It must be noted that casting is not always successful, and resulting value may be Null if thing is not really an object of derived class. In this case, success is guaranteed because of previous check (e.thing is "BasicArmorPickup").
Нужно отметить, что преобразование типов не всегда может быть успешным, и результат может быть Null, если thing на самом деле не является объектом унаследованного класса. В данном случае, успех гарантирован, потому что перед преобразованием уже есть проверка (e.thing is "BasicArmorPickup").
Here is the working example of the code. I only replaced armor_amount and health_amount variables with Console.Printf for code to be more simple.
Вот пример работающего кода. Я только заменил armor_amount и health_amount на Console.Printf, чтобы код был проще.
debug.pk3
You do not have the required permissions to view the files attached to this post.