ID:147258
 
What im trying do is if a mob is in a particular region he/she will get a region report for that region instead of the same report for all.

mob/Login()
usr.action = "login"
usr.loc = locate(1,1,1)

world/New()
..()
spawn() region_info()

proc/region_info(M as mob in /area/region/hondoria)
if(usr.loc == locate(/area))
M << "blah!"
if(usr.loc == locate(/area/region/hondoria))
spawn while(1) // infinite loop
sleep rand(40,60)
M << "Region Report: Hondora"


As soon as I login I get this runtime error:

proc name: region info (/proc/region_info)
source file: initialization.dm,30
usr: null
src: null
call stack:
region info(null)
: New()
1. You don't need the "as mob in /area/blah" stuff, because it's a proc, not a verb. That stuff doesn't have any effect on procs. (And in any case, you should use locate(/area/region/hondoria) instead.)

2. Instead, you would define the argument to region as "mob/M". That means you won't get compiler errors when you try to do things like M.loc.

3. Don't use usr in procs. In this case, use M.loc instead. The reason you would have got compiler errors when you tried M.loc before was because you hadn't defined it as in #2. The actual problem wasn't the M.loc bit, it was the definition of M that was wrong.

4. You're trying to do a region report for a single mob in region_info(), but you're calling it as if you want it to do the report for all mobs. Either method works, but you need to be consistent. =)

5. As your proc stands, even if it was correct it wouldn't work as you want it to. It would check M's location WHEN THE PROC WAS CALLED, and forevermore send M region reports for that region, rather than the region they're actually in at the time.

6. I'd recommend a different system anyway. There's a handy feature in BYOND that is useful here: If you send a text message to an atom, everything in the atom's contents (and its' contents' contents, and so on) gets the text message as well. So you can actually just send the message to the area, and it will automatically display it to everyone in that area. Spiffy, huh? =)

That also means you can get away with having just one loop. Which means less CPU usage, which is a Good Thing(tm). We can optimise it even further, though, by avoiding looping through the whole world to find our areas. We can use a list to keep track of the areas instead, like this:

var/list/allregions=list()

area/region
New()
allregions+=src // Add this area to the regions list
..() // Continue creating area
Del()
allregions-=src // Remove this area from the regions list
..() // Continue deleting area


Then the rest of the region info system can be simple, elegant, and ultra-optimised! It even slices and dices! (I made that last part up.)

world/New()
..()
spawn() region_info()

proc/region_info()
while(1) // Infinite loop; world/New() already spawned us off, so this is fairly safe
// Use the regions list we built up earlier, to avoid the slowness of looping through the entire world
for (var/area/region/A in allregions)
// Send the region report to the region (and therefore everyone in the region)
A << "Region report: [A]"
// Sleep for 40-60 seconds
sleep(rand(400,600))


I took the liberty of increasing the amount to sleep for. The sleep amount is in 1/10 seconds, so 40 actually means 4 seconds, and I'm guessing a report every 4-6 seconds would be annoying. =) You can of course change the delay to whatever you want.

Phew! What an essay. Hope that helped.
In response to Crispy
From using the len variable I see that every square block on the map is of its own.

Every area square has it's own list on it when all the squares should be acting like one.

Ex:

Every square you go, even though I places npcs on the map displays the population as 1.

What I want to do is display the total number of usrs and npcs on a area/region square weather it be connected to eachother or 1,000,000 squares away.

Ex:

Bob logs in and is at 1,1,1 in the Hondorian Region while Jim is at 10,9,1 in the Hondorian Region. Michael is also in the Hondorian Region at 15,15,1. The total population on the region report is 3 users + 5 npcs(random number I picked out) = 8 (because there are also 5 npcs in the same area).
In response to Crispy
Would it be easier to keep a list of variables in all the area squares with Enter() and Exit()?