first, we define our language:
right,# - turn right with the following impulse
foward,# - go forward with the following impulse
then, we create a small program. this should make the object move in a circle.
CODE
list program = ["right,5", "forward,10"];
now we need a way to execute the program. we'll use a timer. we'll also set the program counter to 0 (start of program).
CODE
state_entry()
{
program_counter = 0;
program_length = llGetListLength(program);
llSetTimerEvent(1);
}
in the timer event we'll process the instructions:
CODE
timer()
{
string instruction = llList2String(program, program_counter);
llMessageLinked(LINK_SET, 0, instruction, NULL_KEY);
program_counter = (program_counter + 1) % program_length;
}
so at this point we are firing link messages containing the instruction, e.g. 'right,5'. all that's left is to make the object respond to the messages.
CODE
link_message(integer sender_num, integer num, string str, key id)
{
string tokens = llParseString2List(str, [","], []);
string token0 = llList2String(tokens, 0);
if (token0 == "right")
{
integer impulse = llList2Integer(tokens, 1);
llApplyImpulse(<impule, 0, 0>, TRUE);
}
else if (token0 == "forward")
{
integer impulse = llList2Integer(tokens, 1);
llApplyImpulse(<0, impulse, 0>, TRUE);
}
}