Difference between revisions of "User:Dora Gustafson/JSON structure facial expression"
m (source trace) |
(Undo revision 1180618 by Kireji Haiku (Talk)) |
||
Line 8: | Line 8: | ||
:The power of JSON shows where the menu is decoded and in the navigation between menus. See the first lines in the listen event handler | :The power of JSON shows where the menu is decoded and in the navigation between menus. See the first lines in the listen event handler | ||
<lsl> | <lsl> | ||
// | // Pose ball and facial expressions, script by Dora Gustafson, Studio Dora 2012 | ||
// | // build on Basic pose ball script. by Dora Gustafson, Studio Dora 2010 | ||
// | // v1.00 Has 10 facial expressions that can be chosen from a menu, chosen by random, | ||
// | // ... looped, has menu reopen and saves camera position | ||
// | // v1.01 wearable. Sit on or attach | ||
// | // v1.02 JSON structured dialog-menu with all 19 facial expressions | ||
// | // Define all menu names and menu button lay-outs | ||
string mDisa = "Disapproval"; | string mDisa = "Disapproval"; | ||
list | list LDisa = ["Home","Open mouth","Disdain","Frown","Tongue out","Anger","Bored"]; | ||
string mChee = "Cheerful"; | string mChee = "Cheerful"; | ||
list | list LChee = ["Home","Kiss","Smile","Toothsmile","Laugh","Surprise","Wink"]; | ||
string mMis = "Miserable"; | |||
list LMis = ["Home","Worry","Afraid","Sad","Cry","Embarrassed","Repulsed","Shrug"]; | |||
string mMis | string mHom = "Home"; | ||
list | list LHom = ["Cheerful","Miserable","Disapproval","Loop","Random"]; | ||
string mHom | |||
list | |||
// | // strided list coupler button name and animation name. The order of strides doesn't matter | ||
list coupling = [ "Afraid", "express_afraid_emote", | |||
list | "Anger", "express_anger_emote", | ||
"Bored", "express_bored_emote", | |||
"Cry", "express_cry_emote", | |||
"Disdain", "express_disdain", | |||
"Embarrassed", "express_embarrassed_emote", | |||
"Frown", "express_frown", | |||
"Kiss", "express_kiss", | |||
"Laugh", "express_laugh_emote", | |||
"Open mouth", "express_open_mouth", | |||
"Repulsed", "express_repulsed_emote", | |||
"Sad", "express_sad_emote", | |||
"Shrug", "express_shrug_emote", | |||
"Smile", "express_smile", | |||
"Surprise", "express_surprise_emote", | |||
"Tongue out", "express_tongue_out", | |||
"Toothsmile", "express_toothsmile", | |||
"Wink", "express_wink_emote", | |||
"Worry", "express_worry_emote" ]; | |||
string | string JSONMenu; | ||
list | list BUTTONS; | ||
key | key sitter; | ||
integer | integer dialogChanal=-532247677; | ||
integer haandtag; | integer haandtag; | ||
string | string menuHead; | ||
integer act | integer act=0; | ||
string | string Fanim = "stand"; | ||
default | default | ||
Line 83: | Line 59: | ||
state_entry() | state_entry() | ||
{ | { | ||
string s1 = llList2Json(JSON_ARRAY, LDisa); | string s1 = llList2Json( JSON_ARRAY, LDisa); | ||
string s2 = llList2Json(JSON_ARRAY, LChee); | string s2 = llList2Json( JSON_ARRAY, LChee); | ||
string s3 = llList2Json(JSON_ARRAY, LMis); | string s3 = llList2Json( JSON_ARRAY, LMis); | ||
string s4 = llList2Json(JSON_ARRAY, LHom); | string s4 = llList2Json( JSON_ARRAY, LHom); | ||
JSONMenu = llList2Json( JSON_OBJECT, [mDisa, s1, mChee, s2, mMis, s3, mHom, s4]+coupling); | |||
JSONMenu | BUTTONS = LHom ; | ||
llSitTarget( <0.0, 0.0, 1.0>, ZERO_ROTATION ); | |||
BUTTONS | |||
llSitTarget(<0.0, 0.0, 1.0>, ZERO_ROTATION); | |||
llSetSitText("Animate"); | llSetSitText("Animate"); | ||
llSetClickAction(CLICK_ACTION_SIT); | llSetClickAction(CLICK_ACTION_SIT); | ||
} | } | ||
attach(key id) | attach(key id) | ||
{ | { | ||
menuHead = | menuHead = llGetScriptName( )+"\nMemory in use: "+(string)llGetUsedMemory()+"\n\nChoose any of 19 facial expressions"; | ||
llSetClickAction(CLICK_ACTION_TOUCH); | llSetClickAction(CLICK_ACTION_TOUCH); | ||
llSetTimerEvent( 0.0 ); | |||
act = 0; | act = 0; | ||
if (id) | if (id) | ||
{ | { | ||
sitter = id; | sitter = id; | ||
llRequestPermissions(sitter , PERMISSION_TRIGGER_ANIMATION | llRequestPermissions( sitter , PERMISSION_TRIGGER_ANIMATION); | ||
} | } | ||
else llListenRemove( haandtag); | |||
} | } | ||
changed(integer change) | changed(integer change) | ||
{ | { | ||
menuHead = llGetScriptName( )+"\nMemory in use: "+(string)llGetUsedMemory()+"\n\n[Page Down] reopens this Dialog Menu\n\nChoose any of 19 facial expressions"; | |||
llSetTimerEvent( 0.0 ); | |||
act = 0; | |||
if (change & CHANGED_LINK) | if (change & CHANGED_LINK) | ||
{ | { | ||
sitter = llAvatarOnSitTarget(); | sitter = llAvatarOnSitTarget() ; | ||
if (sitter != NULL_KEY) | if(sitter != NULL_KEY) llRequestPermissions( sitter , PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS | PERMISSION_TRACK_CAMERA); | ||
else | else | ||
{ | { | ||
if ( | if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) llStopAnimation(Fanim); | ||
llSetAlpha(1.0, ALL_SIDES); // show prim | llSetAlpha(1.0, ALL_SIDES); // show prim | ||
llListenRemove(haandtag); | llListenRemove( haandtag); | ||
} | } | ||
} | } | ||
} | } | ||
run_time_permissions(integer perm) | run_time_permissions(integer perm) | ||
{ | { | ||
if ((perm & PERMISSION_TRIGGER_ANIMATION) && (llAvatarOnSitTarget() != NULL_KEY)) | if ( (perm & PERMISSION_TRIGGER_ANIMATION) && (llAvatarOnSitTarget() != NULL_KEY) ) | ||
{ | { | ||
llSetAlpha(0.0, ALL_SIDES); // hide prim | llSetAlpha(0.0, ALL_SIDES); // hide prim | ||
Line 153: | Line 107: | ||
llStopAnimation("sit"); | llStopAnimation("sit"); | ||
} | } | ||
if (perm & PERMISSION_TAKE_CONTROLS) | if ( perm & PERMISSION_TAKE_CONTROLS ) | ||
{ | { | ||
llTakeControls(CONTROL_DOWN , TRUE, TRUE); | llTakeControls( CONTROL_DOWN , TRUE, TRUE); | ||
llListenRemove(haandtag); | llListenRemove( haandtag); | ||
haandtag = llListen( | haandtag = llListen( dialogChanal, "", sitter, ""); | ||
llDialog(sitter, menuHead, BUTTONS, | llDialog( sitter, menuHead, BUTTONS, dialogChanal); | ||
} | } | ||
} | } | ||
touch_end( integer num ) | |||
touch_end(integer | |||
{ | { | ||
if ( llDetectedKey(0) == sitter ) | |||
{ | { | ||
llListenRemove(haandtag); | llListenRemove( haandtag); | ||
haandtag = llListen( | haandtag = llListen( dialogChanal, "", sitter, ""); | ||
llDialog(sitter, menuHead, BUTTONS, | llDialog( sitter, menuHead, BUTTONS, dialogChanal); | ||
} | } | ||
} | } | ||
control(key id, integer down, integer new) | control(key id, integer down, integer new) | ||
{ | { | ||
if (down & new & CONTROL_DOWN) | if ( down & new & CONTROL_DOWN ) llDialog( sitter, menuHead, BUTTONS, dialogChanal); | ||
} | } | ||
listen( integer channel, string name, key id, string message) | |||
listen(integer channel, string name, key id, string message) | |||
{ | { | ||
if ( JSON_ARRAY == llJsonValueType( JSONMenu, [message])) BUTTONS = llParseString2List( llJsonGetValue( JSONMenu, [message]),[",","[","]","\""],[]); | |||
if (JSON_ARRAY == llJsonValueType(JSONMenu, [message])) | |||
else | else | ||
{ | { | ||
if (JSON_STRING == llJsonValueType(JSONMenu, [message])) | if ( JSON_STRING == llJsonValueType( JSONMenu, [message])) Fanim = llJsonGetValue( JSONMenu, [message]); | ||
else if ( "Loop" == message ) | |||
else if ("Loop" == message) | |||
{ | { | ||
act = act ^ 1; | act = act ^ 1; | ||
if ( act & 1 ) llSetTimerEvent( 3.0 ); | |||
if (act & 1) llSetTimerEvent(3.0); | else llSetTimerEvent( 0.0 ); | ||
else | |||
} | } | ||
else if ("Random" == message) | else if ( "Random" == message ) | ||
{ | { | ||
Fanim = llList2String(llListRandomize(coupling, 2), 1); | Fanim = llList2String( llListRandomize( coupling, 2), 1); | ||
act = act ^ 2; | act = act ^ 2; | ||
} | } | ||
if ( | if ( llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) llStartAnimation( Fanim); | ||
} | } | ||
llDialog(sitter, menuHead, BUTTONS, | llDialog( sitter, menuHead, BUTTONS, dialogChanal); | ||
if( | if( llGetPermissions() & PERMISSION_TRACK_CAMERA) | ||
{ | { | ||
rotation cam_rot = llGetCameraRot()/ | rotation cam_rot=llGetCameraRot()/llGetRot(); // relative camera rotation | ||
vector | vector cam_pos=(llGetCameraPos()-llGetPos())/llGetRot(); // relative camera position | ||
llSetLinkCamera(LINK_THIS, cam_pos, cam_pos + llRot2Fwd(cam_rot)); | llSetLinkCamera( LINK_THIS, cam_pos, cam_pos + llRot2Fwd(cam_rot)); | ||
} | } | ||
} | } | ||
timer() | timer() | ||
{ | { | ||
if ( act & 2 ) Fanim = llList2String( llListRandomize( coupling, 2), 1); | |||
if ( llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) llStartAnimation( Fanim); | |||
} | } | ||
} | } |
Revision as of 15:44, 10 August 2013
The script has 19 facial expressions that can be chosen from a menu
- The expressions can also be chosen by random and they can be played in a loop
- The script can be used in a pose ball or in an attached (HUD)prim
- When used for a pose ball the camera position is saved for next session
The script features a JSON structured dialog-menu
- In this case the menu has one main page and three child pages
- The power of JSON shows where the menu is decoded and in the navigation between menus. See the first lines in the listen event handler
<lsl> // Pose ball and facial expressions, script by Dora Gustafson, Studio Dora 2012 // build on Basic pose ball script. by Dora Gustafson, Studio Dora 2010 // v1.00 Has 10 facial expressions that can be chosen from a menu, chosen by random, // ... looped, has menu reopen and saves camera position // v1.01 wearable. Sit on or attach // v1.02 JSON structured dialog-menu with all 19 facial expressions
// Define all menu names and menu button lay-outs string mDisa = "Disapproval"; list LDisa = ["Home","Open mouth","Disdain","Frown","Tongue out","Anger","Bored"]; string mChee = "Cheerful"; list LChee = ["Home","Kiss","Smile","Toothsmile","Laugh","Surprise","Wink"]; string mMis = "Miserable"; list LMis = ["Home","Worry","Afraid","Sad","Cry","Embarrassed","Repulsed","Shrug"]; string mHom = "Home"; list LHom = ["Cheerful","Miserable","Disapproval","Loop","Random"];
// strided list coupler button name and animation name. The order of strides doesn't matter list coupling = [ "Afraid", "express_afraid_emote",
"Anger", "express_anger_emote", "Bored", "express_bored_emote", "Cry", "express_cry_emote", "Disdain", "express_disdain", "Embarrassed", "express_embarrassed_emote", "Frown", "express_frown", "Kiss", "express_kiss", "Laugh", "express_laugh_emote", "Open mouth", "express_open_mouth", "Repulsed", "express_repulsed_emote", "Sad", "express_sad_emote", "Shrug", "express_shrug_emote", "Smile", "express_smile", "Surprise", "express_surprise_emote", "Tongue out", "express_tongue_out", "Toothsmile", "express_toothsmile", "Wink", "express_wink_emote", "Worry", "express_worry_emote" ];
string JSONMenu; list BUTTONS; key sitter; integer dialogChanal=-532247677; integer haandtag; string menuHead; integer act=0; string Fanim = "stand";
default {
state_entry() { string s1 = llList2Json( JSON_ARRAY, LDisa); string s2 = llList2Json( JSON_ARRAY, LChee); string s3 = llList2Json( JSON_ARRAY, LMis); string s4 = llList2Json( JSON_ARRAY, LHom); JSONMenu = llList2Json( JSON_OBJECT, [mDisa, s1, mChee, s2, mMis, s3, mHom, s4]+coupling); BUTTONS = LHom ; llSitTarget( <0.0, 0.0, 1.0>, ZERO_ROTATION ); llSetSitText("Animate"); llSetClickAction(CLICK_ACTION_SIT); } attach(key id) { menuHead = llGetScriptName( )+"\nMemory in use: "+(string)llGetUsedMemory()+"\n\nChoose any of 19 facial expressions"; llSetClickAction(CLICK_ACTION_TOUCH); llSetTimerEvent( 0.0 ); act = 0; if (id) { sitter = id; llRequestPermissions( sitter , PERMISSION_TRIGGER_ANIMATION); } else llListenRemove( haandtag); } changed(integer change) { menuHead = llGetScriptName( )+"\nMemory in use: "+(string)llGetUsedMemory()+"\n\n[Page Down] reopens this Dialog Menu\n\nChoose any of 19 facial expressions"; llSetTimerEvent( 0.0 ); act = 0; if (change & CHANGED_LINK) { sitter = llAvatarOnSitTarget() ; if(sitter != NULL_KEY) llRequestPermissions( sitter , PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS | PERMISSION_TRACK_CAMERA); else { if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) llStopAnimation(Fanim); llSetAlpha(1.0, ALL_SIDES); // show prim llListenRemove( haandtag); } } } run_time_permissions(integer perm) { if ( (perm & PERMISSION_TRIGGER_ANIMATION) && (llAvatarOnSitTarget() != NULL_KEY) ) { llSetAlpha(0.0, ALL_SIDES); // hide prim llStartAnimation(Fanim); llStopAnimation("sit"); } if ( perm & PERMISSION_TAKE_CONTROLS ) { llTakeControls( CONTROL_DOWN , TRUE, TRUE); llListenRemove( haandtag); haandtag = llListen( dialogChanal, "", sitter, ""); llDialog( sitter, menuHead, BUTTONS, dialogChanal); } } touch_end( integer num ) { if ( llDetectedKey(0) == sitter ) { llListenRemove( haandtag); haandtag = llListen( dialogChanal, "", sitter, ""); llDialog( sitter, menuHead, BUTTONS, dialogChanal); } } control(key id, integer down, integer new) { if ( down & new & CONTROL_DOWN ) llDialog( sitter, menuHead, BUTTONS, dialogChanal); } listen( integer channel, string name, key id, string message) { if ( JSON_ARRAY == llJsonValueType( JSONMenu, [message])) BUTTONS = llParseString2List( llJsonGetValue( JSONMenu, [message]),[",","[","]","\""],[]); else { if ( JSON_STRING == llJsonValueType( JSONMenu, [message])) Fanim = llJsonGetValue( JSONMenu, [message]); else if ( "Loop" == message ) { act = act ^ 1; if ( act & 1 ) llSetTimerEvent( 3.0 ); else llSetTimerEvent( 0.0 ); } else if ( "Random" == message ) { Fanim = llList2String( llListRandomize( coupling, 2), 1); act = act ^ 2; } if ( llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) llStartAnimation( Fanim); } llDialog( sitter, menuHead, BUTTONS, dialogChanal); if( llGetPermissions() & PERMISSION_TRACK_CAMERA) { rotation cam_rot=llGetCameraRot()/llGetRot(); // relative camera rotation vector cam_pos=(llGetCameraPos()-llGetPos())/llGetRot(); // relative camera position llSetLinkCamera( LINK_THIS, cam_pos, cam_pos + llRot2Fwd(cam_rot)); } } timer() { if ( act & 2 ) Fanim = llList2String( llListRandomize( coupling, 2), 1); if ( llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) llStartAnimation( Fanim); }
} </lsl> This code has been changed by Kireji Haiku and is not equal to my code, so I can't guarantee it's value. Dora Gustafson 14:18, 9 August 2013 (PDT)