Friday, June 27, 2008

Second Life Script - Number Texture Display #2

Once I had a working number I had to place a few of them in sequence and allow a master prim to control them.



I had to first have a way for the root prim (the scoreboard) to send a message to the individual numbers telling them to update their display. I did this with a link message.


integer MSG_SET_NUM = 141; // arbitray message number
link_message(integer from, integer msg_id, string str, key id)
{
if (msg_id == MSG_SET_NUM)
{
curval = (integer)str;
llOwnerSay("setting num to "+(string)curval);
doOffset();
}
}


Then in the root prim I had to find the individual link numbers of the linked numbers. This is done like this. You first iterate through the list of links and find the ones named 1,10,100,1000 and save their link number. An avatar siting on the item will have a key and will have the highes link number so you have to skip them.

integer thousands = -1;
integer hundreds = -1;
...
state_entry()
{
integer current_link_nr = llGetNumberOfPrims();
// Check if it's more than one
if (1 <>0)
{
if (llGetLinkName(current_link_nr)=="1")
{
llOwnerSay("found 1: "+(string)current_link_nr);
one = current_link_nr;
}
else if (llGetLinkName(current_link_nr)=="10")
{
ten = current_link_nr;
llOwnerSay("found 10: "+(string)current_link_nr);
}
....
current_link_nr--;
}
}
}


Then when the number is changed, you send get the value of the thousands, then hundreds, then tens, then ones and send each on to the various number displays.



integer MSG_SET_NUM = 141; // the same message id defined in the number
doSendNumbers()
{
integer itmp = curval;
if (itmp>10000)
itmp=9999;

integer i;
i = itmp / 1000;
llOwnerSay("thousands = "+(string)i);
if (thousand!=-1)
{
// send the value to the thousands number
llMessageLinked(thousand, MSG_SET_NUM, (string)i, NULL_KEY);
}
itmp = itmp - (i*1000);

i = itmp / 100;
llOwnerSay("hundreds = "+(string)i);
if (hundred!=-1)
{
llMessageLinked(hundred, MSG_SET_NUM, (string)i, NULL_KEY);
}
itmp = itmp - (i*100);
.....


I had one more method on the scoreboard. When an avatar touches the scoreboard I increment the value and send the value out to the various individual numbers.

touch_start(integer total_number)
{
curval++;
if (curval>9999)
curval = 0;

doSendNumbers();
}

No comments: