ID:2069973
 
(See the best response by Nadrew.)
Code:
mob/verb/TextSpeed()
set hidden = 1
if(usr.Talking==TRUE)
for(var/HUD/Text/Te in client.screen)
Te.maptext = null
usr.Talking=FALSE
del(Te)


Problem description:
For some reason I keep getting this runtime error when trying to delete text-boxes after to skip dialog/close the dialog box. It deletes fine, but for some reason the runtime error still happens.

I can't figure out how to fix it.

runtime error: Cannot modify null.maptext.
proc name: Text (/proc/Text)
usr: Peter Mayhew (/mob)
src: null
usr.loc: (6,8,3) (/turf/floors/floor1)
call stack:
Text(Peter Mayhew (/mob), "Doctor Montgomery: Plea...")
Montgomery (/mob/NPC/Montgomery): Interact()


Best response
I'd imagine something in the code is causing one of the loop-overs to trigger after the deletion, a simple if(Te) would prevent the runtime error. However, I don't recommend deleting the things at all, for most efficiency you should be hiding and showing the boxes as needed (removing and adding to/from client.screen) and holding references to the objects to reuse later. The process of creation and deletion is more costly than just holding the objects in memory and using them when they're needed.
In response to Nadrew
Awesome thanks!
I don't recommend deleting the things at all

FTFY.

Manual deletion should always be avoided. Manual deletion is slow because it has to search every variable of every object in the world until the deleted object no longer has any references left.

In order to speed up manual deletion, you should be clearing references to the object. Once you've done this, though, there's no point to manual deletion at all because the very next frame after you clear all the references, the object will be garbage collected.

But yeah, generally understanding the garbage collector and keeping track of objects you need/no longer need is something that you should really familiarize yourself with early in your programming career.