ID:150893
 
world/New()
..()
SpawnTick()

var/obj_count = 0
var/max_obj_count = 5

proc/SpawnTick()
if(obj_count < max_obj_count)
var/mob/Lizard_Man/O = new
var/list/L = new
for(var/turf/T in locate(/area/Lizard_Man))
L += T
if(L.len)
O.loc = L[rand(1,L.len)]
max_obj_count++

spawn(50) SpawnTick()

Ok, what I was hoping was that this code would make sure there were always 5 'lizard men' within the Lizard_Man area. Eg/ If there arnt 5 cause one was either killed or wandered outside the area, a new one would spawn at a random point within. But what happens instead is that it just keeps spawning the little sods and where theres no space left they spawn on top of each other. I tried changing:

max_obj_count++

to just:

obj_count++

but then a certain number would spawn (5) and then no more. What can I do to fix this?
On 7/9/01 7:31 am Botman wrote:
world/New()
..()
SpawnTick()

var/obj_count = 0
var/max_obj_count = 5

proc/SpawnTick()
if(obj_count < max_obj_count)
var/mob/Lizard_Man/O = new
var/list/L = new
for(var/turf/T in locate(/area/Lizard_Man))
L += T
if(L.len)
O.loc = L[rand(1,L.len)]
max_obj_count++

spawn(50) SpawnTick()

Ok, what I was hoping was that this code would make sure there were always 5 'lizard men' within the Lizard_Man area. Eg/ If there arnt 5 cause one was either killed or wandered outside the area, a new one would spawn at a random point within. But what happens instead is that it just keeps spawning the little sods and where theres no space left they spawn on top of each other. I tried changing:

max_obj_count++

to just:

obj_count++

but then a certain number would spawn (5) and then no more. What can I do to fix this?

It needs to be obj_count++
unless your code decrements obj_count whenever a lizard man is killed, obj_count will stay 5.

You need something like this:
mob/Lizard_Man
Del()
obj_count--
..()
In response to Shadowdarke
On 7/9/01 7:48 am Shadowdarke wrote:
On 7/9/01 7:31 am Botman wrote:
world/New()
..()
SpawnTick()

var/obj_count = 0
var/max_obj_count = 5

proc/SpawnTick()
if(obj_count < max_obj_count)
var/mob/Lizard_Man/O = new
var/list/L = new
for(var/turf/T in locate(/area/Lizard_Man))
L += T
if(L.len)
O.loc = L[rand(1,L.len)]
max_obj_count++

spawn(50) SpawnTick()

Ok, what I was hoping was that this code would make sure there were always 5 'lizard men' within the Lizard_Man area. Eg/ If there arnt 5 cause one was either killed or wandered outside the area, a new one would spawn at a random point within. But what happens instead is that it just keeps spawning the little sods and where theres no space left they spawn on top of each other. I tried changing:

max_obj_count++

to just:

obj_count++

but then a certain number would spawn (5) and then no more. What can I do to fix this?

It needs to be obj_count++
unless your code decrements obj_count whenever a lizard man is killed, obj_count will stay 5.

You need something like this:
mob/Lizard_Man
Del()
obj_count--
..()

This is a perfect place to point out something that most people seem to forget: the computer isn't magical, and it isn't telepathic. Not saying that to be rude to you, Botman... but the mistake you made here is that you made the variables, obj_count and max_obj_count, with the idea that it would go up when a lizardman appears and down when one is gone... but you never shared the second part of that idea with the computer! It's probably the most common single group of mistakes made by people who understand the programming language but don't have a lot of experience.
In response to LexyBitch

This is a perfect place to point out something that most people seem to forget: the computer isn't magical, and it isn't telepathic. Not saying that to be rude to you, Botman... but the mistake you made here is that you made the variables, obj_count and max_obj_count, with the idea that it would go up when a lizardman appears and down when one is gone... but you never shared the second part of that idea with the computer! It's probably the most common single group of mistakes made by people who understand the programming language but don't have a lot of experience.

Actually, to tell the truth, I'm kinda happy now (and not just cause Shadowdarke fixed my code, but thanks for that =) ). See I went through the code trying to find the problem, and I came to the conclusion that the problem was I hadn't told it to to reduce the object count when a lizard man died. The next problem was I didn't know how to fix that if it was infact the problem. (I have alot fo problems =) )

Anyway, being able to identify the problem is a far cry from being able to fix them, but I'm still happy cause I got part of the way.

Thanks 2 u both.
In response to Botman
On 7/9/01 8:03 am Botman wrote:
Thanks 2 u both.

I'm happy to help and very grateful that you use our snippets and comments to learn. :)
In response to LexyBitch
On 7/9/01 7:57 am LexyBitch wrote:
This is a perfect place to point out something that most people seem to forget: the computer isn't magical, and it isn't telepathic. Not saying that to be rude to you, Botman... but the mistake you made here is that you made the variables, obj_count and max_obj_count, with the idea that it would go up when a lizardman appears and down when one is gone... but you never shared the second part of that idea with the computer!

If it's any comfort to newbies, in my experience this problem never completely goes away. You just get better at recognizing what happened...
In response to Deadron
On 7/9/01 9:19 am Deadron wrote:
On 7/9/01 7:57 am LexyBitch wrote:
This is a perfect place to point out something that most people seem to forget: the computer isn't magical, and it isn't telepathic. Not saying that to be rude to you, Botman... but the mistake you made here is that you made the variables, obj_count and max_obj_count, with the idea that it would go up when a lizardman appears and down when one is gone... but you never shared the second part of that idea with the computer!

If it's any comfort to newbies, in my experience this problem never completely goes away. You just get better at recognizing what happened...

I did pretty much the same thing yesterday.

"But I DID subtract from the variable! Why isn't it decreasing?"

[look at code]

"That's gotta be a bug. There's no other way."

[look at code]

"Wait a minute."

[look at code]

"Aw, s***."


(Turns out, I was doing var/num = num--, rather than editing the src's num var.)
In response to Spuzzum

I did pretty much the same thing yesterday.

"But I DID subtract from the variable! Why isn't it decreasing?"

[look at code]

"That's gotta be a bug. There's no other way."

[look at code]

"Wait a minute."

[look at code]

"Aw, s***."

Hehehehe