Page 1 of 1

How to set group masking to "hide all"?

Posted: Mon Jun 14, 2010 3:04 pm
by ponysmasher
I've managed to set other settings of layers with a script but not that.

How are you supposed to write it?

Posted: Mon Jun 14, 2010 3:52 pm
by Rai López
If you only want to set that setting, without get into GUI's and similar, I think you can look at the bottom of the "scripts/menu/Layer Effects/lm_layershadow.lua script to figure it out. Fortunately, you'll be able to find (generally) something closely related (or not) with you are treating to do somewhere inside all that AS scripts, so always it worths to take some time scrutinizing them before star to write blindly. A mine of wisdom and (saved) time ;).

Posted: Mon Jun 14, 2010 10:42 pm
by heyvern
I think it's kind of tricky. Are you using the script reference HTML help files availabe in the script forum? Very handy.

Here's the description in the reference to change the masking of a group layer:
void SetGroupMask(mask)

Sets the group's masking mode. See group masking mode constants.
Return value: none mask (int): the group's masking mode
The first thing you need is the layer reference. If you have done scripty things with layers than you know how to get the layer reference. Then you have to tell lua what type of layer it should be used as:
GroupLayer LayerAsGroup(layer)

Converts a generic layer object into a group layer.
Return value (GroupLayer): a GroupLayer object layer (MohoLayer): the layer to cast
So if you've done a lot of scripting you know this part:

Code: Select all

local layer = moho.layer
That is the current layer selected. If that layer is a group layer and you want to change the masking tell lua what type of layer you want the current layer to be referenced as:

Code: Select all

layer = moho:LayerAsGroup(layer)
Once you've done that you can do group layer stuff to "layer". Even if "layer" was a group layer, AS lua isn't going to know that. You have to tell it specifically to work with a group layer.

Now you can set the masking... I hope this works. Haven't tested it but it's the same as other layer type stuff I've done before.

Code: Select all

layer:SetGroupMask(2)
This should set the masking mode of the current layer to "hide all". In the script reference the following are listed as masking options.
The following constants are used to define the masking that happens within a group.


GROUP_MASK_NONE - No masking
GROUP_MASK_SHOW_ALL - Turn on masking, initially showing all sub-layers
GROUP_MASK_HIDE_ALL - Turn on masking, initially hiding all sub-layers
remember that you need an INTEGER for the masking reference. The numbers always start with 0 so "hide all" would be 2:

Hope this is not too confusing. ;)

-vern

Posted: Mon Jun 14, 2010 11:36 pm
by Genete
Now you can set the masking... I hope this works. Haven't tested it but it's the same as other layer type stuff I've done before.

Code: Select all

layer:SetGroupMask(2)
This should set the masking mode of the current layer to "hide all". In the script reference the following are listed as masking options.
The following constants are used to define the masking that happens within a group.


GROUP_MASK_NONE - No masking
GROUP_MASK_SHOW_ALL - Turn on masking, initially showing all sub-layers
GROUP_MASK_HIDE_ALL - Turn on masking, initially hiding all sub-layers
I would use:

Code: Select all

layer:SetGroupMask(GROUP_MASK_HIDE_ALL)
because in the future that value can change and if you hard code the value you are assuming that they won't change. That's the reason those constants are defined. Also the code is more "human readable" ;)
-G

Posted: Tue Jun 15, 2010 2:04 am
by ponysmasher
Thank you for all the help, it works now!

I was doing it like this: layer:SetGroupMask(GROUP_MASK_HIDE_ALL)
But realized it had to be: layer:SetGroupMask(MOHO.GROUP_MASK_HIDE_ALL)

It does say that in the documentation on closer inspection... :oops:

Doing it Verns way, layer:SetGroupMask(2), worked as well of course.

Posted: Tue Jun 15, 2010 9:57 am
by heyvern
I have found that some of the constants in other areas of the reference don't work using the "text" version. I forget which one it was but I spent ages bug testing my code only to find that using the integer worked but the text didn't.

So, if down the road it's not working... check that. ;)

-vern