ID:268775
 
BYOND Version:
Latest
Operating System:
Windows XP
Web Browser:
Exploer
Game/Hub(s): hub://

Detailed Problem Description:
when ever i open dream seeker in my game after i put in the house system it says this BYOND(341.877) ERROR: maximum number of lists exceeded (65535)! if i diaable thecode it works if i dont it says that

Code Snippet to Reproduce Problem (enclose in DM tags):
obj
var
saveX = 0
saveY = 0
saveZ = 0
turf
var
saveX = 0
saveY = 0
saveZ = 0
list
owner = list()

doormatt
Enter(mob/M)
if(src.owner.len == 0)
switch(alert(M,"Do you wish to buy this house?","Buying House","Yes","No"))
if("Yes")
M<<"Welcome to your new house"
src.owner.Add(M.key)
return 1
if("No")
return 0
else
if(M.key in src.owner)
return 1
else
M<<"This isn't your house!!!"
return 0
var/list/HouseStuff = list()
world/New()
if(fexists("House.sav"))
var/savefile/F = new("House.sav")
F >> HouseStuff
for(var/obj/O in HouseStuff)
if(istype(O,/obj))
O.loc = locate(O.saveX,O.saveY,O.saveZ)
for(var/turf/T in HouseStuff)
if(istype(T,/turf/doormatt))
for(var/turf/S in world)
if(istype(S,/turf/doormatt))
if(S.loc == locate(T.saveX,T.saveY,T.saveZ))
S.owner = T.owner
HouseStuff.Remove(T)
world/Del()
var/savefile/F
F = new("House.sav")
for(var/turf/T in world)
if(istype(T,/turf/doormatt))
T.saveX = T.x
T.saveY = T.y
T.saveZ = T.z
HouseStuff.Add(T)
if(istype(T,/turf/tiles/housefloor))
for(var/obj/O in T)
O.saveX = O.x
O.saveY = O.y
O.saveZ = O.z
HouseStuff.Add(O)
F << HouseStuff


Does the problem occur:
Every time? Or how often?
everytime
In other games?
no
On other computers?
yes
In other user accounts?
yes
This is not a bug. It is merely the result of bad list management.

You've created a list, owner, and defined it for every single turf. First of all, there's no way you'd need such a list to be initialized for every single turf; in most cases it could be null. Secondly, for most cases where you're concerned about ownership, a turf is not the place to store that information because it's not as if that changes so much on a turf-by-turf basis as by assigned plots. The turf should be part of something else, an area being the easiest choice, that stores that information.

Lummox JR
In response to Lummox JR
ok so i put

        list
owner = null


And it didnt show the error any more but now when i enter the matt it gives me a ruine time

runtime error: Cannot read null.len
proc name: Enter (/turf/doormatt/Enter)
source file: House.dm,16
usr: Dave (/mob/Player/Saiyan)
src: the doormatt (17,124,1) (/turf/doormatt)
call stack:
the doormatt (17,124,1) (/turf/doormatt): Enter(Dave (/mob/Player/Saiyan))
Dave (/mob/Player/Saiyan): Move(the doormatt (17,124,1) (/turf/doormatt), 1)

and when i log out

runtime error: Cannot execute null.Add().
proc name: Del (/world/Del)
source file: House.dm,55
usr: null
src:
call stack:
: Del()
In response to Dranzer_Solo
Handling this error is simple. If the list is null, it was never set and thus there's no owner. All you have to do is check against whether the list is null or empty. If the list hasn't been set yet and you need to add an owner to it, set the var to list() before adding the owner. Likewise if you lose an owner, you can reset the list to null if it becomes empty.

But like I said, you have a bigger problem to attend to first. Your var is stored in the wrong place to begin with, because a house is an entity covering multiple turfs. The house should be defined as an area or a datum, and it--not the turfs within--should have the owner list. Each turf can simply look up its area (loc) or house datum as needed. I recommend the area approach because it's a lot easier for this task.

Lummox JR
In response to Lummox JR
i got the area instead of turf part but i didnt get the onwer part
In response to Dranzer_Solo
Which owner part? If you mean the first paragraph, Lummox meant you can do this kind of thing:

turf
var
list/owner=null

Enter(atom/movable/A)
if (!ismob(A)) return ..() // Default action for non-mobs
var/mob/M=A // "Type cast" to /mob
if (!owner || !length(owner))
A << "Nobody owns this house. It's now yours!"
// (I'm skipping out the buying bit for simplicity.)
owner=list() // Notice this line!
owner.Add(M.key) // Make them the owner
else
if (owner.Find(M.key))
A << "Welcome to your house, dude!"
return ..()
else
A << "Not your house! Go away!"
return 0


Notice how I checked to see if owner was equal to null, and if it was I made sure to set it to list() before trying to do anything to it. That way, you only make a list object when you need it.

All of the above is irrelevant, though, because just doing it with areas like Lummox mentioned is a much better solution. Using areas, you won't have to worry about conserving lists so much.
In response to Crispy
OOOO i C now ok thanks i undertsnad it now Everything worked now accept for when i log out

runtime error: Cannot execute null.Add().
proc name: Del (/world/Del)
source file: House.dm,58
usr: null
src:
call stack:
: Del()

i counted 57 lines and it came up to this part

HouseStuff.Add(T)
In response to Dranzer_Solo
hmm why does this run time keep poping up? ive been trying to figure this out for the bast hour
In response to Dranzer_Solo
Same reason as what crispy said above. Don't bump if it hasn't been 24 hrs.
In response to N1ghtW1ng
i didnt bump ?!?! ive been workin on the code for like an hour and i forgot i already posted that i just need to get the code done
In response to Dranzer_Solo
How could you forget...if you responded to your own post.
In response to N1ghtW1ng
i dun know -_- by not paying atteion? but anyway back to the point
In response to Dranzer_Solo
Dranzer_Solo wrote:
i dun know -_- by not paying atteion? but anyway back to the point

Actually, the fact that you're not paying attention is kinda the point itself. I already told you how to avoid the runtime error you're now having. The reason you get a problem with null.Add() is that you're trying to use Add() on a list that you haven't initialized. The var is null by default. When the var is null, you need create a new list() before adding to it. For example:
var/list/mylist       // null by default

...

if(!mylist) mylist = new // create the list
mylist += something

Now that said, your excuse for that bump is one of the poorest I've seen. You knew that was too soon. I know it's frustrating when you're banging your head trying to figure out a code problem and you have to wait for an answer, but you still do have to wait it out. (Or you can always reread the existing posts carefully, which would have answered your question. I've found that to be the case for myself many times.) The forums are not real-time, so if you're not getting the answers you need soon enough, just chill out a bit. Please don't bump posts before 24 hours and not until they're off the first page.

Lummox JR
In response to Dranzer_Solo
Dranzer_Solo wrote:
OOOO i C now ok thanks i undertsnad it now Everything worked now accept for when i log out

runtime error: Cannot execute null.Add().
proc name: Del (/world/Del)
source file: House.dm,58
usr: null
src:
call stack:
: Del()

i counted 57 lines and it came up to this part

> HouseStuff.Add(T)
>

You could just use Ctrl+G and type in the line number.
In response to Lummox JR
I Still Dont Get this list crap and ok


well i kinda do i changed everything to area i dont get the tuntime error any more but now it just dosent save

var/list/HouseStuff = list()
world/New()
if(fexists("House.sav"))
var/savefile/F = new("House.sav")
F >> HouseStuff
for(var/obj/O in HouseStuff)
if(istype(O,/obj))
O.loc = locate(O.saveX,O.saveY,O.saveZ)
for(var/turf/T in HouseStuff)
if(istype(T,/area/))
for(var/turf/S in world)
if(istype(S,/area/))
if(S.loc == locate(T.saveX,T.saveY,T.saveZ))
S.owner = T.owner
HouseStuff.Remove(T)
world/Del()
var/savefile/F
F = new("House.sav")
for(var/turf/T in world)
if(istype(T,/area/))
T.saveX = T.x
T.saveY = T.y
T.saveZ = T.z
HouseStuff.Add(T)
if(istype(T,/area/))
for(var/obj/O in T)
O.saveX = O.x
O.saveY = O.y
O.saveZ = O.z
HouseStuff.Add(O)
F << HouseStuff