Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

A-Life help

Monkey Edge
Registered User
Join date: 23 Apr 2005
Posts: 69
08-16-2006 10:47
well i've been working on a script from the wiki for scaling objects and moving them to the right position, and i have this script to make a plant grow during the day and stop at night but im stuck on the reproducing part, i asked around and some say they use llEmail but i dont understand how when the thing that collides to spread the pollen(lets say a bee) they communicate if it can carry pollen, if the plant is old/healthy enough for reproducing,color and other such things like max age and max size.

All help appreciated


heres the code thats in all of the prims
CODE
default {
link_message(integer sender_num, integer num, string str, key id) {
float scale; // size factor
list primparams;

scale = (float)str;

primparams = [];

primparams += [PRIM_SIZE, llGetScale() * scale]; // resize

if (llGetLinkNumber() > 1) { // only move if we're not the root object
primparams += [PRIM_POSITION, llGetLocalPos() * scale]; // reposition
llSetPrimitiveParams(primparams);
}
else
{
llSetPrimitiveParams(primparams);
vector blah=llGetPos();
vector scale=llGetScale();
float z=llGround(<0,0,0>)+4.5*scale.z;
llSetPos(<blah.x,blah.y,z>);
}


}
}


and heres the code thats in the main prim
CODE
// rescales the linked set by the specified factor. factor > 1 makes it larger, < 1 smaller
// example: "/9 2.5"
integer TimerInterval =15;
float GrowthFactor = 0.1;
Resize(float scale) {
integer num_prims = llGetNumberOfPrims();
integer i;

for (i = 1; i <= num_prims; i++) { // first prim in a linked set is 1
llMessageLinked(i, 0, (string)scale, NULL_KEY);
}

}

default
{
state_entry()
{
llListen(9, "", llGetOwner(), "");
llSetTimerEvent(TimerInterval);
}
timer()
{
vector sun=llGetSunDirection();
vector size=llGetScale();
if (llVecMag(size)<7.5)
{
if (sun.z>0.7)
{
Resize(sun.z*1.5);
}
else if (sun.z<0.7 && sun.z>0.4)
{
Resize(sun.z*2);
}
}
}
listen(integer channel, string name, key id, string message)
{
float scale;

scale = (float)message;
if ( scale == 0.0 ) return; // we don't resize by factor 0.0

llSay(0, "Resizing by factor " + (string)scale);

Resize(scale);
}
}
_____________________
What do today what you can put off till tommorrow
But.......
What is today but yesterday's tommorrow
Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
08-16-2006 11:04
Are you saying the bees (being physic enabled) will collide with the flower at some point?
Monkey Edge
Registered User
Join date: 23 Apr 2005
Posts: 69
08-16-2006 11:11
well since i've never done anything much that moves around and "Flys" at some point they will fly around and collide with the flowers if i could ever figure out the script
_____________________
What do today what you can put off till tommorrow
But.......
What is today but yesterday's tommorrow
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-16-2006 11:24
Let's just call them bees and flowers for now (though I'm thinking we sould throw a reference to birds in somewhere...). If you are scripting both the bees and the flowers, you can have them communicate directly with chat messages (probably 'llWhisper()' would be sufficient for this application). Upon collision, have ONE of them (I'll assume the flower for now) issue a query to the other. So for example the flower will use a well-known channel to communicate something like the following:
<collisionKey>;<plantType>;<pollenType>;<givingReceiving>

where:
<collisionKey> - the key of the object that collided with the flower. This is so bees can immediately discard any messages due to other collisions.
<plantType> - This is some type (or group of types, such as genus and species or whatever). Some bees may only be able to pollinate certain types of flower, so the bee can use this information to discriminate if it is appropriate.
<pollenType> - For bees that do not discriminate based on the type of plant or need additional discrimination, this may provide some hints (such as the part of the, "bee," that is pollinated, the length and shape of beak required for, "bees," that are actually hummingbirds, etc.).
<givingReceiving> - This is a set of status values (possibly a bitfied, but for readability it might be better to use strings) indicating whether the flower has pollen to give the bee, will accept pollen from the bee, or both.

Note that the fllower MIGHT only send this message if it is itself ready to reproduce (it is mature, it is the right time of day/"year", has pollen available if this part is male, or whatever). Then again, it might send a message indicating it is not giving and not receiving so that bees can have some kind of memory about where to return or something (possibly additional info such as WHY the plant isn't currently giving/receiving could be used if you really want to get detailed).

The bee, when it receives one of these messages, can respond with a message of its own (IF it decides it can and is ready to give/receive pollen for this plant):
<flowerKey>;<deliveredPollen>;<receivedPollen>

where:
<flowerKey> - The key of the flower from which the above message was received; used to filter messages.
<deliveredPollen> - If the bee is currently carrying pollen (of the appropriate type; this can be kept track of in the bee itself and the initial message can be used to test for matches) this field is used to give some to the plant IF the plant indicated it is currently receiving pollen above.
<receivedPollen> - If the bee is ready to receive pollen and the plant indicated it is currently giving it out, this field indicates that the bee has taken some (may be used for flowers to decide whether they are, "out," of pollen, used for debugging and statistical purposes, or whatever).

You could also decide to give additional information, such as they key of the flower from which pollen was originially received or something.

Does that give you a starting point? If you AREN'T creating the scripts in both the, "flowers," and the, "bees," you might have to use an outside database to keep track of what, "bees" (in this case they could even be avatars or something...), are currently carrying pollen and of what type.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-16-2006 11:33
Oh. BTW if the timing would be sufficient you COULD use 'llEmail()' instead of chat messages (at which point you could drop the keys from the message contents if you wanted), but I suspect it will not really help in terms of lag and such; from what I recall sending e-mail is also some significant work server-side.

I forgot to mention that all of the above doesn't really help the bees actually FIND the flowers. For that you have a wide variety of choices: have programmed routes; use sensors in the bees and filter based on some kind of naming scheme (LAG warning!); have flowers periodically shout on a well-known channel (unlike the above messages, this doesn't have to be directed toward a particular bee; it might also have info such as the type of plant and/or criteria such as color, scent, etc.); have an outside database keep track of flower locations; etc.
Monkey Edge
Registered User
Join date: 23 Apr 2005
Posts: 69
08-16-2006 11:34
well i want to make the bees, and i am already making the flowers hence the scripts i gave,

and correct me if im wrong, but dont bees eat polen or nector? and if so then i could use a hunger varible for checking if the bee is ready to pollinate, and since i have a headache now i'll work on this some more later

thanks for the help and i'll try to combine this into the scripts i have or make some more
_____________________
What do today what you can put off till tommorrow
But.......
What is today but yesterday's tommorrow
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-16-2006 11:38
From: Monkey Edge
well i want to make the bees, and i am already making the flowers hence the scripts i gave,

and correct me if im wrong, but dont bees eat polen or nector? and if so then i could use a hunger varible for checking if the bee is ready to pollinate, and since i have a headache now i'll work on this some more later

Eat/collect nectar and receive/deliver pollen (incidental for a real insect perhaps, but key to our design). The nector isn't really important for this design; we just assume it is there to attract the insect (the flower could broadcast messages to allow the insect to find it only if it has nectar I suppose...).

From: someone
thanks for the help and i'll try to combine this into the scripts i have or make some more

No problem. It is a fun problem to think about.
Monkey Edge
Registered User
Join date: 23 Apr 2005
Posts: 69
08-16-2006 11:44
From: Hewee Zetkin

No problem. It is a fun problem to think about.


not for me, my brain hurts :D
_____________________
What do today what you can put off till tommorrow
But.......
What is today but yesterday's tommorrow
Monkey Edge
Registered User
Join date: 23 Apr 2005
Posts: 69
08-16-2006 12:30
From: Monkey Edge
well since i've never done anything much that moves around and "Flys" at some point they will fly around and collide with the flowers if i could ever figure out the script


well since i've never done roaming things before, how would i go about making a bee that roams around the place? llMoeToTarget? llApplyImpulse? im clueless as to the best way, its going to be physical and i'll probably set bouyancy, but thats about as far as i get before im confused as too the best way to do this, and again all help appreciated
_____________________
What do today what you can put off till tommorrow
But.......
What is today but yesterday's tommorrow
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
08-16-2006 15:14
MoveToTarget then when at_target then call another MoveToTarget then when it hears the plant make it MoveToTarget to that :) You get the idea !
Monkey Edge
Registered User
Join date: 23 Apr 2005
Posts: 69
08-16-2006 16:53
pick a random target?
_____________________
What do today what you can put off till tommorrow
But.......
What is today but yesterday's tommorrow
Ginge Reymont
Registered User
Join date: 10 Oct 2005
Posts: 190
08-16-2006 23:29
Yes so i guess if you only wanted it to roam within 20m or so at the start you would do something like:
integer max = 20;
Homepos = llGetPos();

Then when it calls a random target then do llMoveToTarget(llGetPos()+<llFrand(max),llFrand(max),llFrand(max)>,0.5);
Monkey Edge
Registered User
Join date: 23 Apr 2005
Posts: 69
08-17-2006 16:56
From: Ginge Reymont
Yes so i guess if you only wanted it to roam within 20m or so at the start you would do something like:
integer max = 20;
Homepos = llGetPos();

Then when it calls a random target then do llMoveToTarget(llGetPos()+<llFrand(max),llFrand(max),llFrand(max)>,0.5);

actually that woudl make it olny go up in the x, y, and z axis, you would have to do this:

llMoveToTarget(llGetPos()+<;(llFrand(max)-llFrand(max),(llFrand(max)-llFrand(max),(llFrand(max)-llFrand(max)>,0.5);

but thanks for the springboard :)
_____________________
What do today what you can put off till tommorrow
But.......
What is today but yesterday's tommorrow