une question de state

Répondre
Partager Rechercher
Bonjour tout le monde!

Je suis sur open sim et tente de faire une adaptation de script disons d'organiser de texture "classique" par un plus ludique que l'interface généralement proposé

Dans mon cas il es notamment composé d'une commode avec 32 tiroirs , chaque tiroir compose une catégorie de texture , j'arrive bien a ouvrir et refermé chaque tiroir en fonction des catégories sélectionnés sauf que voila si mon tiroir es déjà ouvert et que je re-clic sur cette catégorie le tiroir ne comprend pas qu'il es déjà ouvert , donc que ma catégorie es déjà sélectionnè et recommence une boucle ouverture et referme encore une fois tout les autres tiroirs qui eu sont deja fermé.

Je sais que je dois lui adresser des états ....je suis déjà ouvert tu me re- sélectionne ok mais je ne fais rien etc etc .... frustration pour moi de savoir quoi faire exactement sans avoir la logique d'écriture pour mettre en application

voila le script en question ( script catégorie texture de l'organiser)

Code PHP:

key GRID_TEX "87dfd082-f83b-673b-e86b-5fa2d64bedf8";

string active_texture;
integer tex_total;
integer page_total;
integer current_page 1;
integer display_total;
integer active;
integer preview1;
integer preview2;
list 
displays;

LOAD_DISPLAYS(list data) {
    
displays = [];
    
integer i;
    
display_total llGetListLength(data);
    for(
i=0i<display_totali++) {
        
displays += (integer)llList2String(datai);
    }
}

list 
GET_LINK_NAMES() {
    list 
names = [""];
    
integer i;
    
integer len llGetNumberOfPrims();
    for(
i=1;i<=len;i++) {
        
names += [llGetLinkName(i)];
    }
    return 
names;
}

GET_PREVIEWS() {
    list 
links GET_LINK_NAMES();
    
displays = [];
    
integer done;
    
integer i 1;
    
preview1 llListFindList(links, ["PREVIEW1"]);
    
preview2 llListFindList(links, ["PREVIEW2"]);
}

LOAD_TEXTURES() {
    
tex_total llGetInventoryNumber(INVENTORY_TEXTURE);
    if(
tex_total == 0) return;
    
page_total = (integer)llCeil((float)tex_total display_total);
}

SET_INDICATOR(vector color) {
   
   
    
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_COLORALL_SIDEScolor1.0PRIM_COLOR0, <1,1,1>, 1.0]);
}

LOAD_PAGE() {
    
integer i;
    
integer offset = (current_page-1) * display_total;
    
integer link;
    
key texture;
    for(
i=0;i<display_total;i++) {
        
link llList2Integer(displaysi);
        
texture GRID_TEX;
        if((
i+offset+1) <= tex_total) {
            
texture llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTUREi+offset));
        }
        
llSetLinkPrimitiveParamsFast(link, [PRIM_TEXTURE0texture, <1,1,0>, <0,0,0>, 0]);
        
//llSetLinkPrimitiveParamsFast(link, [PRIM_TEXT, (string)(i+offset+1), <1,1,1>, 1.0]);
    
}
    
string text "Displaying " + (string)(((current_page-1) * display_total)+1) + "-";
    if((
current_page display_total) > tex_totaltext += (string)tex_total;
    else 
text += (string)(current_page display_total);
    
text += " of " + (string)tex_total " textures";
    
llSetLinkPrimitiveParamsFast(LINK_ROOT, [PRIM_TEXTtext, <1,1,1>, 1.0]);
    
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_TEXTllGetObjectDesc(), <1,1,1>, 1.0]);
}

SET_PREVIEW(integer index) {
    
integer offset = (current_page-1) * display_total;
    
key texture GRID_TEX;
    if((
index+offset+1) <= tex_total) {
        
active_texture llGetInventoryName(INVENTORY_TEXTUREindex+offset);
        
texture llGetInventoryKey(active_texture);
    }
    if(
preview1 == || preview2 == 0) {
        
GET_PREVIEWS();
    }
    
llSetLinkPrimitiveParamsFast(preview1, [PRIM_TEXTURE0texture, <1,1,0>, <0,0,0>, 0]);
    
llSetLinkPrimitiveParamsFast(preview2, [PRIM_TEXTURE0texture, <3,3,0>, <0,0,0>, 0]);
    
}

default {
    
state_entry() {
        
llSetTimerEvent(1);
        
GET_PREVIEWS();
    }
    
    
link_message(integer linkinteger numstring querykey data) {
        if(
link == LINK_ROOT) {
            if(
query == "SEND DISPLAY DATA") {
                
llSetTimerEvent(0);
                
LOAD_DISPLAYS(llCSV2List(data));
                
state loading;
            }
        }
    }
    
    
timer() {
        
llSetTimerEvent(0);
        
llMessageLinked(LINK_ROOT0"REQUEST DISPLAY DATA""");
    }
}

state loading {
    
state_entry() {
        
LOAD_TEXTURES();
        if(
tex_total == 0SET_INDICATOR(<1,0,0>);
        else {
            
            
state ready;
        }
    }
    
    
link_message(integer linkinteger numstring querykey data) {
        if(
link == LINK_ROOT) {
            if(
query == "SEND DISPLAY DATA") {
                
LOAD_DISPLAYS(llCSV2List(data));
                return;
            }
            if(
query == "SET ACTIVE") {
                
llOwnerSay("No textures in this category");
            }
        }
    }
    
    
changed(integer change) {
        if(
change CHANGED_INVENTORY) {
            
LOAD_TEXTURES();
            if(
tex_total != 0state ready;
        }
    }
}

state ready {
    
state_entry() {
        
string desc llList2String(llGetLinkPrimitiveParams(LINK_ROOT, [PRIM_DESC]), 0);
        if((integer)
desc == llGetLinkNumber()) {
            
active TRUE;
            
llMessageLinked(LINK_ALL_OTHERS0"SET ACTIVE""");
            
current_page 1;
            
LOAD_PAGE();
            
SET_PREVIEW(0);
        } else {
            
           
SET_INDICATOR(<1,1,0>);
        }
    }
    
    
link_message(integer linkinteger numstring querykey data) {
        if(
link == LINK_ROOT) {
            if(
query == "SEND DISPLAY DATA") {
                
LOAD_DISPLAYS(llCSV2List(data));
                return;
            }
            if(
query == "RESET") {
                
llResetScript();
                return;
            }
            if(
query == "SEND PREVIEW DATA") {
                list 
previews llCSV2List(data);
                
preview1 = (integer)llList2String(previews0);
                
preview2 = (integer)llList2String(previews1);
                return;
            }
            if(
query == "SET PREVIEW") {
                
SET_PREVIEW(num);
                return;
            }
            
            if(
query == "GIVE TEXTURE") {
                
llGiveInventory(dataactive_texture);
                return;
            }
        }
        
        if(
query == "SET ACTIVE") {
            if(
link == LINK_ROOT)
             {
                 
                
llOwnerSay("tirroir 1, je suis le tirroir selectionné  , je m'ouvre" );
                 
llSetPos(llGetLocalPos()+<0.5,-0.5,0>);
                
SET_INDICATOR(<0,1,0>); //vert
                
active TRUE;
                
current_page 1;
                
LOAD_PAGE();
                
SET_PREVIEW(0);
                
llMessageLinked(LINK_ALL_OTHERS0"SET ACTIVE""");
            }
             else 
             {
                 
                
//tirroir fermé
                
llOwnerSay("tirroir1, tu as changé de catégorie , je me ferme" );
                 
llSetPos(llGetLocalPos()+<-0.5,0.5,0>);
                
SET_INDICATOR(<0.009909,0.062843,0.990091>); //bleu
                
active FALSE;
            }
            return;
        }
        
        if(
query == "BUTTON") {
                 if(
data == "FIRST"current_page 1;
            else if(
data == "PREV"current_page--;
            else if(
data == "NEXT"current_page++;
            else if(
data == "LAST"current_page page_total;
            if(
current_page <= 0current_page page_total;
            if(
current_page page_totalcurrent_page 1;
            
LOAD_PAGE();
        }
    }
    
    
changed(integer change) {
        if(
change CHANGED_INVENTORY) {
            
LOAD_TEXTURES();
            if(
active == TRUE) {
                if(
tex_total == 0state loading;
                else {
                    
LOAD_PAGE();
                }
            }
        } else if(
change CHANGED_LINK) {
            
GET_PREVIEWS();
        }
    }

La partie utile pour mon problème ce trouve pratiquement a la fin du script .

Pas faute de vouloir tenté de comprendre la logique d'état dans un script ....enfin surtout la méthode d'écriture mais la , une fois de plus , je suis perdu !

d'avance merci pour vos réponses.
Bonjour, t as un integer active qui est soit TRUE soit FALSE selon que le tirroir est ouvert ou fermé.....rajoute après chaque "query" un petit if(active==TRUE) .....je suis déjà ouvert, je fais rien, else ....je suis fermé je m 'ouvre.
Merci de ta réponse et de ton aide MenthalOh ;-)

Oui donc a première vue je ne suis pas sur la bonne piste , j'ai donc tenté ta proposition bon on va dire que j'ai une légère amélioration la , au moins le tiroir ne cherche plus a s'ouvrir deux fois si je sélectionne une catégorie déjà sélectionné mais malgré tout il se referme ....bon , après il ne communique plus avec chaque tiroirs mince .....

voila ou j'en suis arrivé :

Code PHP:

key GRID_TEX "87dfd082-f83b-673b-e86b-5fa2d64bedf8";

string active_texture;
integer tex_total;
integer page_total;
integer current_page 1;
integer display_total;
integer active;
integer preview1;
integer preview2;
list 
displays;

LOAD_DISPLAYS(list data) {
    
displays = [];
    
integer i;
    
display_total llGetListLength(data);
    for(
i=0i<display_totali++) {
        
displays += (integer)llList2String(datai);
    }
}

list 
GET_LINK_NAMES() {
    list 
names = [""];
    
integer i;
    
integer len llGetNumberOfPrims();
    for(
i=1;i<=len;i++) {
        
names += [llGetLinkName(i)];
    }
    return 
names;
}

GET_PREVIEWS() {
    list 
links GET_LINK_NAMES();
    
displays = [];
    
integer done;
    
integer i 1;
    
preview1 llListFindList(links, ["PREVIEW1"]);
    
preview2 llListFindList(links, ["PREVIEW2"]);
}

LOAD_TEXTURES() {
    
tex_total llGetInventoryNumber(INVENTORY_TEXTURE);
    if(
tex_total == 0) return;
    
page_total = (integer)llCeil((float)tex_total display_total);
}

SET_INDICATOR(vector color) {
   
   
    
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_COLORALL_SIDEScolor1.0PRIM_COLOR0, <1,1,1>, 1.0]);
}

LOAD_PAGE() {
    
integer i;
    
integer offset = (current_page-1) * display_total;
    
integer link;
    
key texture;
    for(
i=0;i<display_total;i++) {
        
link llList2Integer(displaysi);
        
texture GRID_TEX;
        if((
i+offset+1) <= tex_total) {
            
texture llGetInventoryKey(llGetInventoryName(INVENTORY_TEXTUREi+offset));
        }
        
llSetLinkPrimitiveParamsFast(link, [PRIM_TEXTURE0texture, <1,1,0>, <0,0,0>, 0]);
        
//llSetLinkPrimitiveParamsFast(link, [PRIM_TEXT, (string)(i+offset+1), <1,1,1>, 1.0]);
    
}
    
string text "Displaying " + (string)(((current_page-1) * display_total)+1) + "-";
    if((
current_page display_total) > tex_totaltext += (string)tex_total;
    else 
text += (string)(current_page display_total);
    
text += " of " + (string)tex_total " textures";
    
llSetLinkPrimitiveParamsFast(LINK_ROOT, [PRIM_TEXTtext, <1,1,1>, 1.0]);
    
llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_TEXTllGetObjectDesc(), <1,1,1>, 1.0]);
}

SET_PREVIEW(integer index) {
    
integer offset = (current_page-1) * display_total;
    
key texture GRID_TEX;
    if((
index+offset+1) <= tex_total) {
        
active_texture llGetInventoryName(INVENTORY_TEXTUREindex+offset);
        
texture llGetInventoryKey(active_texture);
    }
    if(
preview1 == || preview2 == 0) {
        
GET_PREVIEWS();
    }
    
llSetLinkPrimitiveParamsFast(preview1, [PRIM_TEXTURE0texture, <1,1,0>, <0,0,0>, 0]);
    
llSetLinkPrimitiveParamsFast(preview2, [PRIM_TEXTURE0texture, <3,3,0>, <0,0,0>, 0]);
    
}

default {
    
state_entry() {
        
llSetTimerEvent(1);
        
GET_PREVIEWS();
    }
    
    
link_message(integer linkinteger numstring querykey data) {
        if(
link == LINK_ROOT) {
            if(
query == "SEND DISPLAY DATA") {
                
llSetTimerEvent(0);
                
LOAD_DISPLAYS(llCSV2List(data));
                
state loading;
            }
        }
    }
    
    
timer() {
        
llSetTimerEvent(0);
        
llMessageLinked(LINK_ROOT0"REQUEST DISPLAY DATA""");
    }
}

state loading {
    
state_entry() {
        
LOAD_TEXTURES();
        if(
tex_total == 0SET_INDICATOR(<1,0,0>);
        else {
            
            
state ready;
        }
    }
    
    
link_message(integer linkinteger numstring querykey data) {
        if(
link == LINK_ROOT) {
            if(
query == "SEND DISPLAY DATA") {
                
LOAD_DISPLAYS(llCSV2List(data));
                return;
            }
            if(
query == "SET ACTIVE") {
                
llOwnerSay("No textures in this category");
            }
        }
    }
    
    
changed(integer change) {
        if(
change CHANGED_INVENTORY) {
            
LOAD_TEXTURES();
            if(
tex_total != 0state ready;
        }
    }
}

state ready {
    
state_entry() {
        
string desc llList2String(llGetLinkPrimitiveParams(LINK_ROOT, [PRIM_DESC]), 0);
        if((integer)
desc == llGetLinkNumber()) {
            
active TRUE;
            
llMessageLinked(LINK_ALL_OTHERS0"SET ACTIVE""");
            
current_page 1;
            
LOAD_PAGE();
            
SET_PREVIEW(0);
        } else {
            
           
SET_INDICATOR(<1,1,0>);
        }
    }
    
    
link_message(integer linkinteger numstring querykey data) {
        if(
link == LINK_ROOT) {
            if(
query == "SEND DISPLAY DATA") {
                
LOAD_DISPLAYS(llCSV2List(data));
                return;
            }
            if(
query == "RESET") {
                
llResetScript();
                return;
            }
            if(
query == "SEND PREVIEW DATA") {
                list 
previews llCSV2List(data);
                
preview1 = (integer)llList2String(previews0);
                
preview2 = (integer)llList2String(previews1);
                return;
            }
            if(
query == "SET PREVIEW") {
                
SET_PREVIEW(num);
                return;
            }
            
            if(
query == "GIVE TEXTURE") {
                
llGiveInventory(dataactive_texture);
                return;
            }
        }
        
        if(
query == "SET ACTIVE") {
            if(
link == LINK_ROOT)
            {
             if(
active==FALSE)
             {
                 
                
llOwnerSay("tirroir 1, je suis le tiroir selectionné  , je m'ouvre" );
                 
llSetPos(llGetLocalPos()+<0.5,-0.5,0>);
                
SET_INDICATOR(<0,1,0>); //vert
                
active TRUE;
                
current_page 1;
                
LOAD_PAGE();
                
SET_PREVIEW(0);
                
llMessageLinked(LINK_ALL_OTHERS0"SET ACTIVE""");
           }
        else
             {
                  if(
active==TRUE)
                  {
                 
                
//tirroir fermé
                
llOwnerSay("tiroir1, tu as changé de catégorie , je me ferme" );
                 
llSetPos(llGetLocalPos()+<-0.5,0.5,0>);
                
SET_INDICATOR(<0.009909,0.062843,0.990091>); //bleu
                
active FALSE;
            }
        }
    }

            return;
        }
        
        if(
query == "BUTTON") {
                 if(
data == "FIRST"current_page 1;
            else if(
data == "PREV"current_page--;
            else if(
data == "NEXT"current_page++;
            else if(
data == "LAST"current_page page_total;
            if(
current_page <= 0current_page page_total;
            if(
current_page page_totalcurrent_page 1;
            
LOAD_PAGE();
        }
    }
    
    
changed(integer change) {
        if(
change CHANGED_INVENTORY) {
            
LOAD_TEXTURES();
            if(
active == TRUE) {
                if(
tex_total == 0state loading;
                else {
                    
LOAD_PAGE();
                }
            }
        } else if(
change CHANGED_LINK) {
            
GET_PREVIEWS();
        }
    }

et plus précisément j'ai modifié cette partie :

Code PHP:

  if(query == "SET ACTIVE") {
            if(
link == LINK_ROOT)
            {
             if(
active==FALSE)
             {
                 
                
llOwnerSay("tirroir 1, je suis le tiroir selectionné  , je m'ouvre" );
                 
llSetPos(llGetLocalPos()+<0.5,-0.5,0>);
                
SET_INDICATOR(<0,1,0>); //vert
                
active TRUE;
                
current_page 1;
                
LOAD_PAGE();
                
SET_PREVIEW(0);
                
llMessageLinked(LINK_ALL_OTHERS0"SET ACTIVE""");
           }
        else
             {
                  if(
active==TRUE)
                  {
                 
                
//tirroir fermé
                
llOwnerSay("tiroir1, tu as changé de catégorie , je me ferme" );
                 
llSetPos(llGetLocalPos()+<-0.5,0.5,0>);
                
SET_INDICATOR(<0.009909,0.062843,0.990091>); //bleu
                
active FALSE;
            }
        }
    } 
Bonsoir tout le monde !

bon , j'ai continué mes recherches , alors a ce que j'arrive a voir avec la solution de MenthalOh, certes le tiroir ne bouge plus dans tout les sens ....mais problème plus du tout , mais je pense aussi que je dois considéré un premier tiroir comme ouvert par défaut non ? ....bon j'avoue je suis complétement largué ...et j'aurais grand besoin de votre aide...
Répondre

Connectés sur ce fil

 
1 connecté (0 membre et 1 invité) Afficher la liste détaillée des connectés