ID:261971
 
When I try to use my own library into a game of mine. I get a type mismatch error on line 187. I imagine anyone(IF anyone) who has even tried using it has encountered the error, too. Here's a link to the library

And... What the hell, here is the code.

    Del() //Now for the boxes deletion
if(C)
for(var/O in Images) //clean up all the images
del(O)
M.box -= src //The player will no longer have that box -- LINE THE ERROR IS ON
if(!M.box) M.box = null //If that was the last one, we need to get rid of the list for memory's sake
..() //Delete that box


The library works normally, but not when incorporated into another program.

Resonating Light
If M.box isn't a list, subtracting an object from it won't work. It's probably null at the point the error occurs. A good simple error check here is to put if(M.box) before that.

Also, your if(!M.box) check is kind of useless; if that if() is true it's because M.box is already null. An empty list is still a true value, so if(!M.box.len) is what you'd really need.

Lummox JR
In response to Lummox JR
I have made sure the list has been intialized before adding anything to it though. Inside of the New() proc for the Box datum. I did if(!M.box) M.box = new. I think I found the problems here at school though. I'll test it again when I get home.

Resonating Light
In response to Resonating_Light
I did what you said to do. And I fixed up the Del() proc just fine. I also fixed a few other problems that arose. Eventually it led into the source of it all. It's because the New() proc isn't working with a world.view such as "12x11". Here's what I have to fix it.

        if(isnum(C.view)) //If the view is one number. e.g -- view = 6
maxx = text2num("[C.view*2+1]") //set maxx and maxy
maxy = text2num("[C.view*2+1]")
else //In case the view is something like -- view = "13x8"
var/xy = findtext(C.view,"x")
maxx = text2num(copytext(C.view,1,xy))
maxy = text2num(copytext(C.view,xy))


I get no errors with that, not even runtime ones. Instead it displays the message in the following code and deletes the Box datum.

        while(maxx < (width+x-1))//If maxx is greater than what the box extends to...
width-- //Then lower it by one
if(width < 1) //Check to see if it's fell below zero...
M << "The box was unsucessfully created due to the position of it's creation" //We gotta let em know
del(src) //If it has, then that means the player won't be able to see the box because of where it was created. So we'll just delete it.
while(maxy < (height+y-1))//Same thing, but for y
height--
if(height < 1)
M << "The box was unsucessfully created due to the position of it's creation" //We gotta let em know
del(src)


That's in case the box's width and height go beyond the clients view, it reduces it's size just enough to fit in the screen.

Resonating Light