PDA

View Full Version : Control ctlactive based on selection



nickdigital
02-08-2013, 02:50 PM
Is it possible to control the active (ctlactive) state of a ctl item based on a selection?

Pseudo code would be:

if (the user has this selected in Layout){
enable this button;
}

else{
don't enable the button;
}

sami
02-08-2013, 05:45 PM
This may be a bit inelegant but it works - doing what you asked - in this case it enables a button based on whether an item called "Null" is selected in the scene:


@version 2.13

var foundItem;
generic
{
var myScene = Scene();
var selItems = myScene.getSelect();

var i = 1;
foundItem = false;
var foundstr = "not selected";
for(i=1;i<selItems.size() + 1;i++)
{
if (selItems[i].name == "Null")
{
foundItem = true;
foundstr = "selected";
break;
}
}


reqbegin("My Requester");
reqsize(500,170);

c1 = ctlbutton("Do something to Null",122,"button_callback_c1");
ctlposition(c1,40,75,122,20);


c2 = ctltext("","Item \"Null\" is "+ foundstr," "," ");
ctlposition(c2,40,20,104,20);

ctlactive(c2, "c1_callback", c1);

return if !reqpost();


reqend();
}
c1_callback:value
{
return foundItem;
}

button_callback_c1
{
// perform processing here
info("Do something to Null");
}

nickdigital
02-08-2013, 05:49 PM
Thanks. I'll dissect this.

sami
02-08-2013, 05:56 PM
not much to it.

Sorry I didn't comment it or make it super clean.

All I do is grab the currently selected items from the scene with the .getSelect() off of the Scene Object agent, then iterate through them looking for my named object I'm looking for, then set a global variable to true or false.
The only tricky bit was since I didn't know of a discrete activate() command in LScript for controls, I used the ctlactive() function - but tied a label's callback to the activating the button and in the callback just send back my globally set variable whether the item was found or not.

nickdigital
02-08-2013, 06:34 PM
Thanks for the description. Definitely learned something new today. :thumbsup: