Logo

[Help] SM5 triggering command of lua childrens

Register Log In Back To Forums

Post #1 · Posted at 2017-01-28 05:40:26pm 7.1 years ago

Offline MadkaT
MadkaT Avatar Member
820 Posts
Not Set
Reg. 2009-11-24


Last updated: 2017-01-28 05:41pm
Hello friends, I'm messing with some icons and I have this trouble:

http://i.imgur.com/c5LuFLA.png

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. Very Happy

Post #2 · Posted at 2017-01-29 12:42:56am 7.1 years ago

Offline FlameyBoy
FlameyBoy Avatar Member
335 Posts
United States
Reg. 2011-03-09

You can use :GetChildren() on whatever contains the objects, and call :queuecommand("On") on those.

Post #3 · Posted at 2017-01-29 05:11:19am 7.1 years ago

Offline MadkaT
MadkaT Avatar Member
820 Posts
Not Set
Reg. 2009-11-24

I've made this abomination of code, but I get an error saying that the queuecommand is nil Dead


LoadActor("../_ModeArt/tut")..{
OnCommand=cmd(addx,-171;addy,36);
GainFocusCommand=function(self)
self:GetChildren():queuecommand("On");
end;
LoseFocusCommand=cmd(playcommand,"On");
};

Post #4 · Posted at 2017-01-29 08:26:32am 7.1 years ago

Offline dbk2
dbk2 Avatar Member
332 Posts
Not Set
Reg. 2012-04-30


Last updated: 2017-01-29 08:33am
Quote: MadkaT
I've made this abomination of code, but I get an error saying that the queuecommand is nil Dead

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 · Posted at 2017-01-29 03:33:31pm 7.1 years ago

Offline MadkaT
MadkaT Avatar Member
820 Posts
Not Set
Reg. 2009-11-24

Hi Dan, I've worked with children actors, but in the same lua file Tongue in this case I'm confused, because the childrens are in another lua file Dead

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;

Post #6 · Posted at 2017-01-30 01:18:59pm 7.1 years ago

Offline dbk2
dbk2 Avatar Member
332 Posts
Not Set
Reg. 2012-04-30


Last updated: 2017-01-30 01:19pm
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;

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),
}

When you call queuecommand() using an ActorFrame, it broadcasts that command to all children actors. Hopefully this makes sense...

Post #7 · Posted at 2017-01-30 09:29:43pm 7.1 years ago

Offline MadkaT
MadkaT Avatar Member
820 Posts
Not Set
Reg. 2009-11-24


Last updated: 2017-01-30 09:30pm
That was too easy, I was complicating myself Laughing Out Loud I'm feeling stupid now. I was thinking on something "special" to this type of behaviour. Thanks for the patience. Very Happy
Register Log In Back To Forums

0 User(s) Viewing This Thread (Past 15 Minutes)

©2006-2024 Zenius -I- vanisher.com -5th style- IIPrivacy Policy
Web Server: 3% · Database: 4% · Server Time: 2024-03-28 13:29:52
This page took 0.007 seconds to execute.
Theme: starlight · Language: englishuk
Reset Theme & Language