Post #1 · Publicado en 2017-01-28 05:40:26pm Hace 7.6 años
Hello friends, I'm messing with some icons and I have this trouble:
I have 2 main actors, the character icon, and the label icons with the circle. I've created the label icons, as an ActorFrame, the label icons are LUA files, and they have some children actors. What I like to do is to trigger the "On" command of the labels children actors, when the character icon is focused, my actual code is this:
--OffComand icon art
LoadActor("../_ModeArt/tut")..{
OnCommand=cmd(addx,-171;addy,36);
GainFocusCommand=cmd(diffusealpha,1);
LoseFocusCommand=cmd(diffusealpha,0);
};
I'm only hidding/showing them, but when I show them, I like to play the "On" command of all the childrens, Is this possible? Thanks for reading.
I have 2 main actors, the character icon, and the label icons with the circle. I've created the label icons, as an ActorFrame, the label icons are LUA files, and they have some children actors. What I like to do is to trigger the "On" command of the labels children actors, when the character icon is focused, my actual code is this:
--OffComand icon art
LoadActor("../_ModeArt/tut")..{
OnCommand=cmd(addx,-171;addy,36);
GainFocusCommand=cmd(diffusealpha,1);
LoseFocusCommand=cmd(diffusealpha,0);
};
I'm only hidding/showing them, but when I show them, I like to play the "On" command of all the childrens, Is this possible? Thanks for reading.
Post #2 · Publicado en 2017-01-29 12:42:56am Hace 7.6 años
FlameyBoy | |
---|---|
Member | |
335 Mensajes | |
Reg. 2011-03-09 | |
You can use :GetChildren() on whatever contains the objects, and call :queuecommand("On") on those.
Post #3 · Publicado en 2017-01-29 05:11:19am Hace 7.6 años
MadkaT | |
---|---|
Member | |
824 Mensajes | |
Not Set | |
Reg. 2009-11-24 | |
I've made this abomination of code, but I get an error saying that the queuecommand is nil
LoadActor("../_ModeArt/tut")..{
OnCommand=cmd(addx,-171;addy,36);
GainFocusCommand=function(self)
self:GetChildren():queuecommand("On");
end;
LoseFocusCommand=cmd(playcommand,"On");
};
LoadActor("../_ModeArt/tut")..{
OnCommand=cmd(addx,-171;addy,36);
GainFocusCommand=function(self)
self:GetChildren():queuecommand("On");
end;
LoseFocusCommand=cmd(playcommand,"On");
};
Post #4 · Publicado en 2017-01-29 08:26:32am Hace 7.6 años
Quote: MadkaT
I've made this abomination of code, but I get an error saying that the queuecommand is nil
The queuecommand isn't nil. You are calling queuecommand on nil.
You code looks like this:
self:GetChildren():queuecommand("On");
The part to think about is self:GetChildren() – what do you think that code does?
It gets children actors that belong to a parent ActorFrame. An ActorFrame (usually) has children. Take a look at the example code in this lesson I wrote:
http://dguzek.github.io/Lua-For-SM5/Introduction/Foreword.html
In that example code, the ActorFrame has three children – a Quad, a BitmapText, and a Sprite. I could call self:GetChildren() if self was referring to that ActorFrame, and I would get a table with three the children in it.
In your code, you are calling GetChildren() on self, where self is referring to LoadActor("../_ModeArt/tut")
Does "../_ModeArt/tut" return an ActorFrame with children?
If so, that would make sense, and that much of your code should work. However, even if that is the case, GetChildren() will return a table of actors, and you can only call queuecommand() on one of those children, not the entire table.
So, something like this might work:
self:GetChildren()[1]:queuecommand("On")
To summarize, there are a few things to keep in mind:
1. You can't call GetChildren() on an Actor, only on an ActorFrame.
2. You can't call queuecommand() on a table, which is what GetChildren() would return if used on an ActorFrame.
Does that make sense?
Post #5 · Publicado en 2017-01-29 03:33:31pm Hace 7.6 años
MadkaT | |
---|---|
Member | |
824 Mensajes | |
Not Set | |
Reg. 2009-11-24 | |
Hi Dan, I've worked with children actors, but in the same lua file in this case I'm confused, because the childrens are in another lua file
Quote: dbk2
Does "../_ModeArt/tut" return an ActorFrame with children?
Yes, this is the code inside the "tut" file:local t = Def.ActorFrame {};
t[#t+1] = Def.ActorFrame {
Def.ActorFrame {
OnCommand=cmd(x,47;y,-3;zoom,0;linear,.084;zoom,1;pulse;effectmagnitude,.75,1,1;);
LoadActor("sptut")..{
OnCommand=cmd(spin;effectmagnitude,0,0,-300;);
};
};
LoadActor("lbltut")..{
OnCommand=cmd(zoomx,1.2;zoomy,.2;linear,.05;zoom,1.2;sleep,0;zoom,1;sleep,0.117;bob;effectperiod,1;effectmagnitude,0,2,0);
};
};
return t;
t[#t+1] = Def.ActorFrame {
Def.ActorFrame {
OnCommand=cmd(x,47;y,-3;zoom,0;linear,.084;zoom,1;pulse;effectmagnitude,.75,1,1;);
LoadActor("sptut")..{
OnCommand=cmd(spin;effectmagnitude,0,0,-300;);
};
};
LoadActor("lbltut")..{
OnCommand=cmd(zoomx,1.2;zoomy,.2;linear,.05;zoom,1.2;sleep,0;zoom,1;sleep,0.117;bob;effectperiod,1;effectmagnitude,0,2,0);
};
};
return t;
Post #6 · Publicado en 2017-01-30 01:18:59pm Hace 7.6 años
Quote: MadkaT
this is the code inside the "tut" file:
local t = Def.ActorFrame {};
t[#t+1] = Def.ActorFrame {
Def.ActorFrame {
OnCommand=cmd(x,47;y,-3;zoom,0;linear,.084;zoom,1;pulse;effectmagnitude,.75,1,1;);
LoadActor("sptut")..{
OnCommand=cmd(spin;effectmagnitude,0,0,-300;);
};
};
LoadActor("lbltut")..{
OnCommand=cmd(zoomx,1.2;zoomy,.2;linear,.05;zoom,1.2;sleep,0;zoom,1;sleep,0.117;bob;effectperiod,1;effectmagnitude,0,2,0);
};
};
return t;
t[#t+1] = Def.ActorFrame {
Def.ActorFrame {
OnCommand=cmd(x,47;y,-3;zoom,0;linear,.084;zoom,1;pulse;effectmagnitude,.75,1,1;);
LoadActor("sptut")..{
OnCommand=cmd(spin;effectmagnitude,0,0,-300;);
};
};
LoadActor("lbltut")..{
OnCommand=cmd(zoomx,1.2;zoomy,.2;linear,.05;zoom,1.2;sleep,0;zoom,1;sleep,0.117;bob;effectperiod,1;effectmagnitude,0,2,0);
};
};
return t;
That code is what is loaded into the parent file when you call LoadActor("../_ModeArt/tut")
So, that code IS the actor that LoadActor("../_ModeArt/tut") represents. It is an ActorFrame, the same ActorFrame that is in the other file. You just have the code separated between two different files.
- - - - - - - -
Anyway, to answer your original question, if you want to re-trigger the OnCommand of all children when the ActorFrame gains focus, you should just be able to do something like this:
Quote
LoadActor("../_ModeArt/tut")..{
OnCommand=cmd(addx,-171;addy,36),
GainFocusCommand=cmd(diffusealpha,1; queuecommand, "On"),
LoseFocusCommand=cmd(diffusealpha,0),
}
OnCommand=cmd(addx,-171;addy,36),
GainFocusCommand=cmd(diffusealpha,1; queuecommand, "On"),
LoseFocusCommand=cmd(diffusealpha,0),
}
When you call queuecommand() using an ActorFrame, it broadcasts that command to all children actors. Hopefully this makes sense...
Post #7 · Publicado en 2017-01-30 09:29:43pm Hace 7.6 años
That was too easy, I was complicating myself I'm feeling stupid now. I was thinking on something "special" to this type of behaviour. Thanks for the patience.