In the quest system im designing, I move a few mobs, objs, whatever to a specific area. The area is defined as follows
var/area/SquirrelArena/SA
and is searched for, right before this like so
for(SA in world)
break
the problem is this:
M.Move(SA.contents[rand(1,SA.contents.len)])
It doesnt move M, and so it stays at a null location. Im wondering exactly why this isnt working. SA.contents is all the stuff inside the area(list), so thats the turfs correct?
and the len just gives me the number of turfs in the area so its between 1 and however many tiles there are? Anyways, I cant see a reason for it not to work. If anyone could tell me why I would be greatful
Alathon
ID:150521
![]() Sep 6 2001, 9:40 am
|
|
Heh, I just discovered in the reference: Area contents also includes the contents of all the turfs in the area! This behaviour is very different from turf, mob, and obj contents lists. That explains a couple unusual instances from Tanks. It does pay to help! :)
You'll need to make a list of the turfs in area contents, then get a random one from within that list. var/list/turflist = list() for(var/turf/T in SA) turflist += T P.loc = turflist[rand(1,turflist.len)] I used P.loc instead of Move() because there are a ton of reasons Move() can fail, leaving P where it started. If you want, you could also filter turfs out of turflist so that they don't start inside walls or places where there is already a mob. |
Deadron wrote:
Alathon wrote: Alright now I know why, have one more question however. If I do like this var/area/SquirrelArea/SA for(SA in world) break If I placed some SquirrelArea on a map, wouldnt it find SA? because thats how I have it atm, and I tried doing some debugging and the for loop is failing. Am I doing it wrong (im still a bit cloudy on how areas to turfs and things around that work) Alathon |
Shadowdarke wrote:
Heh, I just discovered in the reference: Area contents also includes the contents of all the turfs in the area! This behaviour is very different from turf, mob, and obj contents lists. That explains a couple unusual instances from Tanks. It does pay to help! :) Ahh, ok. Thanks once again Shadowdarke! :) Alathon |
that's how I did it in Tanks and the Outside Area Demo. the easiest way to see if it's working is to put a debug message after the loop
world << "SA:[SA]" (Make sure you have some text with it, so you recognize what's going on if it's null.) |
Shadowdarke wrote:
that's how I did it in Tanks and the Outside Area Demo. the easiest way to see if it's working is to put a debug message after the loop it works! halleluja, or however thats spelled. Well, almost, 3 out of 5 of what is spawning is missing, but..some of em appear, so yay! :) And yeah, I was doing some debugging but for some reason it didnt show that for(SA in world) was working, and it obviously was cuz It can find SA for the turf thing. Alathon |
for index out of bounds, perhaps you should run the loop from 0, to length - 1, rather than 1 to length
|
Cybergen wrote:
for index out of bounds, perhaps you should run the loop from 0, to length - 1, rather than 1 to length Hmm...Alright, thanks Alathon |
Cybergen wrote:
for index out of bounds, perhaps you should run the loop from 0, to length - 1, rather than 1 to length DM lists are 1-based, not 0-based. |
Do some testing...loop through the contents of an area and list the type of each thing you encounter.
Or override Move() to print out a message indicating why it didn't work.