I have built a small presentation screen with two navigation buttons. The whole communication between the buttons and the screen takes place using the llMessageLinked-function. Each slide have to be placed as texture into the prim of the mainscreen. The textures have to be numbered in the order in which they should be displayed later.
The script of the screen also informs the buttons when the last slide has been reached. So that the “next”-prim is not able to navigate anymore. The “previous” and “next” prim have nearly the same scriptcode, except that the one checks if the first slide has been reached and the other looks out for the last slide.
The lsl-code for the “previous” button looks like this.
integer slideToDisplay;
integer firstSlideReached;
integer currentSlide;
default
{
state_entry() {
firstSlideReached = 1;
slideToDisplay = 1;
currentSlide = 1;
llSetTexture("da79968e-b8b7-8a0a-cc66-2a717e9c3d41", 4);
llRotateTexture(PI, 4);
}
touch_start(integer total_number)
{
if(firstSlideReached == 0) {
slideToDisplay = currentSlide - 1;
llMessageLinked(LINK_SET,slideToDisplay,"slideToDisplay",NULL_KEY);
} else {
llSay(0, "First slide reached.");
}
}
link_message(integer sender_num, integer num, string str, key id) {
if(str == "currentSlide") {
currentSlide = num;
if(currentSlide == 1) {
firstSlideReached = 1;
} else {
firstSlideReached = 0;
}
}
}
}
The “next” prim code looks like this. It also uses a “arrow”-texture which is included via a key in the state_entry()-function. The “previous” button uses the same texture only rotated in another rotation.
integer slideToDisplay;
integer lastSlideReached;
integer currentSlide;
integer maxSlide;
default
{
state_entry() {
lastSlideReached = 0;
slideToDisplay = 1;
currentSlide = 1;
maxSlide = 1000;
llSetTexture("da79968e-b8b7-8a0a-cc66-2a717e9c3d41", 4);
}
touch_start(integer total_number)
{
if(lastSlideReached == 0) {
slideToDisplay = currentSlide + 1;
llMessageLinked(LINK_SET,slideToDisplay,"slideToDisplay",NULL_KEY);
} else {
llSay(0, "Last slide reached.");
}
}
link_message(integer sender_num, integer num, string str, key id) {
if(str == "currentSlide") {
currentSlide = num;
if(currentSlide < maxSlide) {
lastSlideReached = 0;
}
}
if(str == "lastSlideReached" && num == 1) {
lastSlideReached = 1;
maxSlide = currentSlide;
}
}
}
The screen itself checks first if a texture is available. If not it sets an test-texture (in this case: some color-circles i did, identified by the unique-key).
integer lastSlideReached;
integer firstSlideReached;
integer currentSlide;
default {
state_entry() {
// check for first slide and set it when available
if(llGetInventoryKey("1") != NULL_KEY) {
llSetTexture("1", 4);
} else {
llSetTexture("b13e131e-13a4-37ad-e137-4b6f81a0a3fa", 4);
}
}
link_message(integer sender_num, integer num, string str, key id) {
if(str == "slideToDisplay") {
string slideToDisplayStr = (string) num;
if(llGetInventoryKey(slideToDisplayStr) != NULL_KEY) {
llSetTexture((string)num, 4);
llMessageLinked(LINK_SET,num,"currentSlide",NULL_KEY);
// check if next slide exists
integer nextSlideNr = num+1;
string nextSlideStr = (string) nextSlideNr;
//llSay(0, "check for next slide nr " + nextSlideStr);
if(llGetInventoryKey(nextSlideStr) == NULL_KEY) {
lastSlideReached = 1;
llMessageLinked(LINK_SET,1,"lastSlideReached",NULL_KEY);
} else {
lastSlideReached = 0;
}
} else {
llSay(0, "Slide not available");
}
}
}
}
With some text-textures the screen will look like this:
On the left side is the test-texture i did, if no slides are available.
No comments:
Post a Comment