Posted February 17, 2022 by GomaGames
#coding
I’ve created a ‘burnable’ “Interface”
item.is_burnable
along with an enum “Primary Material” so that anything wooden that gets thrown in the fire will burn.
In oop world, one way to achieve multiple inheritance is to define an abstract type that defines behaviors as method signatures. The interface is “what methods can I call on this object that implements this interface”. I can define an interface named
Pet
that says “any class that implementsPet
must have the functionswalk()
,eat()
, andpet()
. So classDog
andCat
canimplement Pet
.
By “oop”, i mean “Object Oriented Programming”
however, gdscript doesn’t support interfaces. gdscript uses duck-typing so i “implement interfaces” the duck typed way.
if object.has_method("method_name"):
do the thing
not shown in demo: a burnable that is not a FireWood will not start a fire
valid FireWood items are "stick_bundle", "wood_fence", "wood", "lumber"