ID:1416798
 
(See the best response by DarkCampainger.)
Hey guys. I'm having a strange issue when trying to output to a grid.

I am using the grid to show the user his/her available spells, which can then be cast by clicking. Here is the code that updates the list of spells:

UpdateSpells()
var/count=1
var/tmp/list/allspells=new()
usr.spells=null
allspells+=new/obj/magic/windbreeze
allspells+=new/obj/magic/windgust
allspells+=new/obj/magic/windblast
allspells+=new/obj/magic/windstorm
allspells+=new/obj/magic/tornado
allspells+=new/obj/magic/cook1
allspells+=new/obj/magic/lightlogs
allspells+=new/obj/magic/fireball
allspells+=new/obj/magic/cook2
allspells+=new/obj/magic/fireblast
allspells+=new/obj/magic/cook3
allspells+=new/obj/magic/firestorm
allspells+=new/obj/magic/breathefire
allspells+=new/obj/magic/waterball
allspells+=new/obj/magic/telekaishi
allspells+=new/obj/magic/telekminor
allspells+=new/obj/magic/heal1
allspells+=new/obj/magic/waterblast
allspells+=new/obj/magic/telesd
allspells+=new/obj/magic/heal2
allspells+=new/obj/magic/telekmajor
allspells+=new/obj/magic/waterstorm
allspells+=new/obj/magic/heal3
allspells+=new/obj/magic/whirlpool
allspells+=new/obj/magic/alchemize1
allspells+=new/obj/magic/deposititem
allspells+=new/obj/magic/alchemize2
allspells+=new/obj/magic/withdrawitem
allspells+=new/obj/magic/alchemize3
for(var/obj/magic/O in allspells)
if(O.levelreq<=usr.magic)
usr<<output(O,"spellswindow.spellsgrid:[count++]")


and here is a picture of what happens:



The strange thing is that everything works perfectly and all of the spells show up properly, but after a few seconds, a few of them change to objs. Each time this happens, it's different spells that transform. Really stumped on this.
Where are those icons being pulled from (the yellow numbers)? It might give some indication where the problem is coming from, seems to me like there's something else in your code conflicting with this.
I have those numbers in a few places, but only on the interface. They are used for showing level and gold on client.screen.
Best response
You're outputting temporary objects to your grid. Being displayed in a grid does not count as a reference, so they get garbage collected and their appearance is recycled.

Skin reference:
Very important: If you send an atom to a grid like you would with a statpanel, keep that object in a list or make sure it actually exists somewhere in the world. Do not use a temporary object that will be deleted when the proc ends, or it can disappear/change in the grid when a new object is created.

Did you intend to set usr.spells to allspells to hold on to them?
Ah, good catch. I didn't notice allspells was a local variable, that would indeed be the problem.
Good call on that one! I'm not sure what the issues is now, though...when I use a non-temporary list, I get a runtime error:

UpdateSpells()
var/count=0
usr.spells=null
usr.spells+=new/obj/magic/windbreeze
usr.spells+=new/obj/magic/windgust
usr.spells+=new/obj/magic/windblast
usr.spells+=new/obj/magic/windstorm
usr.spells+=new/obj/magic/tornado
usr.spells+=new/obj/magic/cook1
usr.spells+=new/obj/magic/lightlogs
usr.spells+=new/obj/magic/fireball
usr.spells+=new/obj/magic/cook2
usr.spells+=new/obj/magic/fireblast
usr.spells+=new/obj/magic/cook3
usr.spells+=new/obj/magic/firestorm
usr.spells+=new/obj/magic/breathefire
usr.spells+=new/obj/magic/waterball
usr.spells+=new/obj/magic/telekaishi
usr.spells+=new/obj/magic/telekminor
usr.spells+=new/obj/magic/heal1
usr.spells+=new/obj/magic/waterblast
usr.spells+=new/obj/magic/telesd
usr.spells+=new/obj/magic/heal2
usr.spells+=new/obj/magic/telekmajor
usr.spells+=new/obj/magic/waterstorm
usr.spells+=new/obj/magic/heal3
usr.spells+=new/obj/magic/whirlpool
usr.spells+=new/obj/magic/alchemize1
usr.spells+=new/obj/magic/deposititem
usr.spells+=new/obj/magic/alchemize2
usr.spells+=new/obj/magic/withdrawitem
usr.spells+=new/obj/magic/alchemize3
for(var/obj/magic/O in usr.spells)
if(O.levelreq<=usr.magic)
usr<<output(O,"spellswindow.spellsgrid:[count++]")


runtime error: type mismatch: Wind Breeze (Level 1) (/obj/magic/windbreeze) += Wind Gust (Level 12) (/obj/magic/windgust)
proc name: UpdateSpells (/mob/proc/UpdateSpells)
usr: TEST (/mob/player)
src: TEST (/mob/player)
call stack:
TEST (/mob/player): UpdateSpells()
TEST (/mob/player): Spells()

It looks to me like it's trying to add the next obj where it should be adding the previous. Any insights?
You didn't create the list: usr.spells=new/list()

null + windbreeze = windbreeze
windbreeze + windgust = undefined operator/type mismatch.
I have the list created elsewhere because it serves other purposes in other places in the code. :/
What DarkCampainger is referring to is the line usr.spells=null.
Yeah, I see it now. Thanks for the help, guys. It's working perfectly now!!