Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

calling function on other prime

syamir Skytower
Registered User
Join date: 16 Jul 2008
Posts: 3
07-24-2008 00:06
hey, i have 2 prime. i need 1 prime to call a function on another prime. is there a way? can u post some example script.

Thank you.
Urrong Urnst
Registered User
Join date: 12 Jul 2008
Posts: 49
07-24-2008 00:08
U can use listen to communicate between prims or if they are linked u can use llMessageLinked.

Example of two UNLINKED (if they are linked it is better to use llMessageLinked) prims communicating.

listening script:

CODE

default
{
state_entry()
{
llListen(3, "", "", "") //will listen on channel 3 for any message and anyone
}
listen(integer channel, string name, key id, string message)
{
message = llToUpper(message); //i used llToUpper to be more noticable
if(message == "COMMAND ON") //tests the message that was heard
llSay(0, "You typed command to initiate me"); //you can add any function that u want
else if(message == "COMMAND OFF") //tests again
llSay(0, "You typed command to shutdown me");
}
}
CODE


saying script:
CODE


integer command = FALSE;
default
{
touch_start(integer num)
{
if(command == FALSE) //checks if command is off
{
llRegionSay(3, "command on"); //says command on on channel 3
command = TRUE;
}
else //else turn it off
{
llRegionSay(3, "command off"); // says command off on channel 3
command = FALSE;
}
}
}
CODE


Scripts werent compiled so there might be some syntax errors.
syamir Skytower
Registered User
Join date: 16 Jul 2008
Posts: 3
07-24-2008 01:18
thanks for the reply. i have this 1 prime which is a score board and 4 prime which will ask user questions. 1 prime 1 question. so total of 4 question. for every question they answer, they will get different score( for example Q1 a = 10 b=15 c=0 d=30). once a user answer a question i want to the score board to update the score. is there a way to let the scoreboard know how much point it suppose to add beside this method? im going to have to make alot more question later on(more than 50).

Thank you.
Urrong Urnst
Registered User
Join date: 12 Jul 2008
Posts: 49
07-24-2008 02:03
Yes in this case u can use llMessageLinked. I dont know what is the point in making 1 prim for one question but ill write an example script. The board will in this case be a cube with floating text

Question prim:

CODE

integer channel = llFrand(1000) +1;
integer listen_handle;
list answer_buttons = ["1", "2", "3"];
string dialog_message = "What LSL stands for? \n\n 1. Linden Second Language \n 2. Linden Scripting Language \n 3. WTF!!!???";
key user;
default
{
touch_start(integer num)
{
channel = llFrand(1000) +1;
listen_handle = llListen(channel, "", llGetKey(),"");
user = llDetectedKey(0);
llDialog(user, dialog_message, answer_buttons, channel);
}

listen(integer ch, string name, key id, string msg)
{
if(msg == "1")
{
llMessageLinked(LINK_SET, 1, "question 1", user);
llListenRemove(listen_handle);
}
else if(msg == "2")
{
llMessageLinked(LINK_SET, 2, "question 1", user);
llListenRemove(listen_handle);
}
else if(msg == "3")
{
llMessageLinked(LINK_SET, 3, "question 1", user);
llListenRemove(listen_handle);
}
}
}
CODE


Board Prim:

CODE

integer points = 0;
default
{
link_message(integer sender_num, integer num, string msg, key id)
{
if((msg == "question 1") && (num == 1))
{
llSay(0, llKey2Name(id)+" answered wrong on question 1. You get 0 points.");
llSetText("Total Points: " + (string)points);
}
else if((msg == "question 1") && (num == 2))
{
llSay(0, llKey2Name(id)+" answered right on question 1. You get 10 points.");
points += 10;
llSetText("Total Points: " + (string)points);
}
else if((msg == "question 1") && (num == 3))
{
llSay(0, llKey2Name(id)+" doesnt have a clue about question 1. You get -5 points.");
points += -5:
llSetText("Total Points: " + (string)points);
}
}
}
CODE


There may be some errors inside because i didnt compile this. In this "version" anyone can answer the question and the points shown will be the total points of all the answers. I didnt put any comment inside so go check the function on lsl wiki or post if u would like me to explain anything.
[/i]
syamir Skytower
Registered User
Join date: 16 Jul 2008
Posts: 3
07-24-2008 02:13
ok i understand now thank you dude