ID:273561
 
Fight()
set hidden=1
var/i=1
var/list/monster_list=(typesof(/mob/monsters)-/mob/monsters)

winshow(usr,"Fight",1)
winset(src,"Fight.Mon","cells=0x0")
src<<output("<b>Choose Monster!</b>","Fight.Mon:1,1")
for(var/A in monster_list)
var/newpath = text2path("[A]")
var/mob/monsters/o = new newpath
src<<output(o.name,"Fight.Mon:1,[++i]")
src<<output(o.Level,"Fight.Mon:2,[i]")


I am using the following to display monsters in the typepath mob/monsters/. I am wanting to be able to click the monster to start a battle with it. What would be the simplest way to to do this, i have tried just adding a Click() on the monster but i get nothing.



Store the list of monsters in some variable that exists outside the proc. Otherwise, they're immediately deleted when the proc ends and therefore clicking won't work.

My GetClick() library would also be a good alternative.
In response to Garthor
Alright I followed your advice.
var/list/Monster=list()
proc
CreateMonsterList()
var/list/monster_list=(typesof(/mob/monsters)-/mob/monsters)

for(var/A in monster_list)
var/newpath = text2path("[A]")
var/mob/monsters/o = new newpath
Monster.Add(o)

Fight()
set hidden=1
var/i=1
winshow(usr,"Fight",1)
winset(src,"Fight.Mon","cells=0x0")
src<<output("<b>Choose Monster!</b>","Fight.Mon:1,1")
for(var/mob/A in Monster)
src<<output(A.name,"Fight.Mon:1,[++i]")
src<<output(A.Level,"Fight.Mon:2,[i]")

mob
monsters
Peasant
HP = 15
MaxHP = 15
Str= 6
Con = 6
Int = 6
Wis = 3
Dex = 6
Luck = 5
Weapon = 2
AttackText = "punches"
AttackText2 = "hits"
Level = 0.5
Click()
world<<"Test"


I still am not getting any feedback from the Click(). Am i storing the mobs wrong in the list or is something else to blame?
In response to National Guardsmen
You're outputting a text and number to the grid, not the actual monster. You'll only be clicking text or a number.
src << output(A, //etc...

Output the monster and it will display the name and icon.
In response to National Guardsmen
Why are you converting a type path to a text string and then back to a type path again? Just do new A() instead of that.

As for your issue: you are only outputting their names to the grid. The name is a text string. Clicking on a text string is not likely to do much.
In response to Garthor
Ah, i see where i was messing up. Thanks for the help.