Jump to content

Having a script listen / change variables on multiple conditions.


ayamashi
 Share

You are about to reply to a thread that has been inactive for 433 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I am having trouble understanding / figuring out how to make a script listen on certain channels on certain conditions.

I have a listener object that listens to the HUD and plays animation depending which anim the user choses..

But I want the HUD to swap between two options - 1. listener only listens to object owner and plays selected animation // 2. When multiple object (HUD) owners press the SYNC button it enables sim wide animation selection. Meaning if 2 or more owners enable the SYNC button, if any object owner choses an animation - it will play the same animation at the same time at once for all owners with SYNC enabled.

1. seems simple...just by having an unique channel for each owner.

I am having troubles with 2 because I dont know if I am missing something or just cant think.

I thought I can just set a toggle for dialogChannel to change depending if SYNC is on/off but that is not really working....

If SYNC is OFF - dialogChannel is unique [ex. dialogChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1))); ].

If SYNC is ON - dialogChannel is some random value, but same for all owners [ex. dialogChannel = 123456]

-----------

HUD script

integer dialogChannel;
integer iSync;

default
{
    changed(integer change)
    {
        (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
  
   state_entry()
    {
        dialogChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)));
    
    }  
  
   touch_start(integer total_number)
    {
      integer link = llDetectedLinkNumber(0);
       integer face = llDetectedTouchFace(0);
     
     if (link == 1) 
        
        {
            iSync =! iSync;
            
            if (face == 0 && iSync) 
            {
                dialogChannel = 123456;
                llOwnerSay("Sync enabled.");
                llRegionSay(dialogChannel, "SyncON");
              	llSay(0, "Channel is + " (string)dialogChannel);
                
            }
            else 
            { 
              	dialogChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)));
                llOwnerSay("Sync disabled.");
                llRegionSay(dialogChannel, "SyncOFF");
              	llSay(0, "Channel is + " (string)dialogChannel);
                
            }
    }

--------------------------

Listener script

integer dialogChannel;
integer listenHandle;
key ownerID;

default
{
     changed(integer change)
    {
        (change & CHANGED_OWNER)
        {
            llResetScript();
            
        }
    }
  
  state_entry()
    {
        
        dialogChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)));
        ownerID = llGetOwner();
        listenHandle = llListen(dChannel, "", "", "");
        llRequestPermissions(ownerID, PERMISSION_TRIGGER_ANIMATION);
    }
  
  run_time_permissions(integer perm)
    
    {
        ownerID = llGetOwner();
        llRequestPermissions(ownerID, PERMISSION_TRIGGER_ANIMATION);
    }
  
  listen(integer channel, string name, key id, string message)
    
    if (message == "SyncON") 
        {
			 dialogChannel = 123456;
             listenHandle = llListen(dialogChannel, "", "", "");
             llSay(0, "Channel is" + (string)dialogChannel);

        }
       else if (message == "SyncOFF") 
        {
             dialogChannel = ((integer)("0x"+llGetSubString((string)llGetOwner(),-8,-1)));
             listenHandle = llListen(dialogChannel, "", "", "");
             llSay(0, "Channel is" + (string)dialogChannel);
        }

-----------

I cant even say what I tried anymore. When I pass the objects to my alt it either works or it doesnt, it either plays animation if its ON or OFF. The HUD works fine if I leave out the SYNC.

Any help?

Thank you!

Edited by ayamashi
Link to comment
Share on other sites

You're opening new listeners, but never closing them when the other is active. It is possible to have multiple listener running at once - one does not override another.

This looked interesting so I threw together a single-script demo for this. It only uses one listener, and differentiates between hearing messages from the owner (via llDialog) and hearing messages from other instances of the HUD (which itself will broadcast the chosen dance when Sync mode is on). The assumption being that everyone in the region will have a copy of the same HUD with the same name.

I didn't have an alt to test with, so I just rezzed two instances of this object, wore one and then move out of chat range from the other.

/*Demo. 
1. Rez two prims, link them together
2. Name Root "HUD Demo"
3. Name Child link "Sync"
4. Drop this script into object root
5. Make a copy of the Hud Object and leave it rezzed
6. Wear the other copy of this object
7. Move at least 10 meters away from the rezzed copy
*/
integer SYNC = FALSE;
integer dChannel = 123; //used for both personal and synced messages

default
{
    state_entry()
    {
        llListen(dChannel, "", "", "");
    }

    touch_start(integer total_number)
    {
        string buttonName = llGetLinkName(llDetectedLinkNumber(0));
        
        if(buttonName=="Sync")
        {
            SYNC = !SYNC;   //toggle HUD sync mode
            llOwnerSay("Sync toggled to: "+llList2String(["FALSE","TRUE"],SYNC));
            return;
        }
        
        llDialog( llGetOwner(), "Select a dance", ["1","2","3","4","5","6","7","8","9"], dChannel );
    }
    
    
    listen(integer channel, string name, key id, string message)
    {
        if(id ==llGetOwner())   //messages from the diloag will have owner's ID
        {
            llOwnerSay("heard llDialog from owner's own hud, playing anim: "+message);
            
            if(SYNC)
            {
                llOwnerSay("Sync is on, boradcasting chosen dance to region...");
                llRegionSay(dChannel,message);
            }
        }
        else if(SYNC && name == llGetObjectName()) //messages from other HUDs will not have owner's ID, but will have HUD's name
        {
            llOwnerSay("heard llDialog from another Synced HUD, playing anim: "+message);
        }
    }
}

 

Edited by Fenix Eldritch
  • Like 1
Link to comment
Share on other sites

If I were implementing this, I think I'd have both listening modes available at the same time, and use llListenControl to switch them:

(untested example code:)

// HUD
integer CHAN_SELF = 1234; // could use pseudo-random generation, but I don't see a benefit.
integer CHAN_SYNC = 4321;

integer gSync = FALSE;

default
{ touch_end(integer n)
  {   if(...)
      {  // sync ON
         gSync = TRUE;
         // assuming the listener is an attachment, it will hear messages directed at the owner:
         llRegionSayTo(llGetOwner(),CHAN_SELF,"SYNC_ON");
      }else if(...)
      {  //sync OFF
         gSYNC = FALSE;
         llRegionSayTo(llGetOwner(),CHAN_SELF,"SYNC_OFF");
      }else if(...)
      {   // send message:
          if(gSync)
          {   llRegionSay(CHAN_SYNC,"msg");
          }else
          {   llRegionSayTo(llGetOwner(),CHAN_SELF,"msg"); 
          }
      }
  }
}

 

// listener
integer CHAN_SELF = 1234;
integer CHAN_SYNC = 4321;

integer gHandleSync;

default
{   state_entry()
    {	llListen(CHAN_SELF,"",llGetOwner(),"");
        gHandleSync = llListen(CHAN_SYNC,"","","");
        llListenControl(gHandleSync,FALSE);
    }
    listen(...)
    {   if("SYNC_ON"==msg)
        {   llListenControl(gHandleSync,TRUE);
        }else if("SYNC_OFF"==msg)
        {   llListenControl(gHandleSync,FALSE);
        }else if(...)
        {
        }
    }
}

 

Edited by Quistess Alpha
  • Like 1
Link to comment
Share on other sites

3 hours ago, ayamashi said:

having an unique channel for each owner.

 

this is the issue.  As wrote, each HUD is broadcasting and listening on their own unique channel, they can't hear the other HUDs when synched

the fix is use a single synch channel which all HUDs listen and broadcast on, as Fenix and Quistess show

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 433 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...