swift - Variable/class in array -


so i'm kinda stuck on somethng. kinda want random drop wen kill monster. got.

i've got weapon1

class weapon {    var str = int } class weapon1: weapon {     override init() {         super.init()  str = 10 } class weapon2: weapon {     override init() {         super.init()  str = 20 } 

i've got monster

class monster {    str = 20    def = 10    drops = [weapon1(), weapon2()] } 

and have place link drops if monster death

var itemdrops = weapon() 

and when monster dies should link monster drop itemdrops.. can use somewhere in inventory. when try this

random = (arc4random_uniform(uint32(monster.items.count-1)))   //-1 becous 2 items , array starts @ 0 itemdrops = monster.items[random] 

but items in white..

the problem items instance property of monster:

class monster {    str = 20    def = 10    drops = [weapon1(), weapon2()] } 

but when try access it, try access through class:

monster.items[random] 

the class monster has no class/static property items, code cannot compile.

this reason using capital letters class names, supposed to. helps keep track of whether thing class or instance. example:

class monster {    str = 20    def = 10    drops = [weapon1(), weapon2()] // assume you've named these classes correctly } 

now, in code, say:

let amonster = monster() // _instance_ var itemdrops = amonster.items[random] 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -