View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:46 am



Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
 Lua and attachables work around. 
Author Message
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Lua and attachables work around.
"Ifs make a 'scope' too."
?


Sun Jun 21, 2009 3:14 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Lua and attachables work around.
Oh, I forgot about scoping.

Still, for speed reasons, it's faster to make one variable then to make it over and over again.


Sun Jun 21, 2009 3:16 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Lua and attachables work around.
Marginally faster, yes. And as much as it is possible to declare the variable again, it can lead to some serious problems in more complicated scripts. I would strongly advise against it.
Another problem with that code is that the for loop goes from 1 to MovableMan:GetMOIDCount. You would want to subtract one from the MOID count, or it will always return the last one as nil.


Sun Jun 21, 2009 7:26 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Lua and attachables work around.
Sorry to bump, but how do you use this to find a specific attachable on an actor that the Lua is applied to?
I don't understand the script.


Wed Oct 21, 2009 7:31 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Lua and attachables work around.
if i understood correctly, you want to run something on an attachable?
right, heres how, from the actor the thing is attached to.
Code:
--in create(), have this block to grab all child objects.
self.attachables = {} -- create a table to put the children into
for i = 1, MovableMan:GetMOIDCount() - 1 do --we have to use getmoidcount -1 to prevent errors
  self.mo = MovableMan:GetMOFromID(i) --get the mo, use self.mo for simplicity
  if self.mo.RootID == self.ID and i ~= self.ID then --if it is a child of us but not us
    table.insert(self.attachables, ToAttachable(self.mo)) --then put it into the table.
  end
end
--then, in update(), have this block, with whatever you want to do in it.
for k,v in ipairs(self.attachables) do --iterates through the table
if string.find(v.PresetName, "INSERT THE PRESETNAME OF THE ONE YOU WANT TO DO STUFF TO HERE") then --find the presetname to identify the object.
v:function() --do stuff on it here
--more stuff here if you want
end
end
there you go. you'll need to add some "IS THE ATTACHABLE STILL ALIVE?" checks, but thats handling attachables in a nutshell.


Wed Oct 21, 2009 8:22 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Lua and attachables work around.
Wonderful!
Can you explain to me what the v:function() is so I understand it in it's entirety so I can mess with it?


Wed Oct 21, 2009 8:38 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Lua and attachables work around.
v is the attachable at this point, you can pass functions and change all the variables that are exposed through it. ipairs iterates the table of attachables and returns k and v as index and value respectively


Wed Oct 21, 2009 9:02 am
Profile WWW
User avatar

Joined: Wed Jan 07, 2009 10:26 am
Posts: 4074
Location: That quaint little British colony down south
Reply with quote
Post Re: Lua and attachables work around.
If you have multiple identically named attachables then I presume you'd need to find another distinguishing factor and switch that into the PresetName checking bit to get it to work, correct?


Wed Oct 21, 2009 9:18 am
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Lua and attachables work around.
You'd just need to make a copy of the object in ini code and give it an A or B or something at the end of it's preset name.

At the beginning when you say put it in a function Create(), can I put it in function Create(self)?

Geti wrote:
you'll need to add some "IS THE ATTACHABLE STILL ALIVE?" checks, but thats handling attachables in a nutshell.

Whats the best way to do that? :/
If v:IsSetToDelete?


Wed Oct 21, 2009 9:31 am
Profile WWW
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Lua and attachables work around.
CrazyMLC wrote:
You'd just need to make a copy of the object in ini code and give it an A or B or something at the end of it's preset name.
Correct, or you could use the parentoffset values, but really, you dont usually get multiples of an attachable. maybe a limb, but we cant do very much with them at the moment anyway <_<
CrazyMLC wrote:
At the beginning when you say put it in a function Create(), can I put it in function Create(self)
That was the intention, yes. Sorry for not being more clear :/
CrazyMLC wrote:
Whats the best way to do that? :/
If v:IsSetToDelete?
Well, I'd suggest a RootID check.
Code:
for k,v in ipairs(self.attachables) do
if string.find(v.PresetName, "INSERT THE PRESETNAME OF THE ONE YOU WANT TO DO STUFF TO HERE") and v.RootID == self.ID then
--do stuff on it here
else
--elseif v.RootID ~= self.ID then --use this rather than plain else if you want to only remove attachables that arent attached anymore.
table.remove(self.attachables, k) --clean up useless pointers so we dont have to keep filtering them out later on
end
end
It should work, im suggesting this because MovableMan:ValidMO(mo) hasnt worked well for me in the past, especially with attachables. note, this might cause errors later cause of the removal of all non-working pointers, im not sure how for handles an empty table..


Wed Oct 21, 2009 10:55 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 25 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.110s | 13 Queries | GZIP : Off ]