hi im new in programing and in processing and i use it with java in oracle, so sorry if my question is dumb or not clear.
so here is my question,
i want to make a reproduction mechanisme for my herbivor (herb3m for male and herb3f for female).
For now everytime a male touch a female, a random number is take and if the condition is make a new herbivor is added. but its not “natural” because some time a lot of “child” are added because of my condition.
what i want is:
when a male touch a female there is a chance of make a “child” (like i do in my code, for me it fine) BUT i want a delay after the first child is born and the next one so there is no demographic explosion.
so how did i make a delay AFTER the first “child” is born ?
Or use else if or you didt that in parent.random() I don’t know.
For the delay you could add a variable in the Herbivor3M/Herbivor3F class and set it to -10000 (for invalid or not used yet). Then you can go like this:
if(parent.random(1) < 0.009 && h3m.lastChildTime() > 10000, && h3f.lastChildTime() > 10000){
//get child
h3m.setLastChildTime(millis());
h3f.setLastChildTime(millis());
}
//variable in Herbivor3M/Herbivor3F class
int lastChildTime = -1;
//functions in Herbivor3M/Herbivor3F class
int lastChildTime() {
return millis() - lastChildTime;
}
void setLastChildTime(int time) {
lastChildTime = time;
}
Hi, sorry I relpy so late but I’m not active here during week ends.
The code I gave you adds another test to the if() before getting a child. In that test…
…it checks whether the last time that specific Herbivor had a child is more than 10 seconds ago. Since the time is measured in milli seconds it’s 10000.
Then when they have a child the time they got their child (in milliseconds) is saved in the variable:
The last function…
returns the difference between the saved time and the actual time. This difference is used in the test of the if() above.
I hope this helps you to understand the code. If not please ask again