View unanswered posts | View active topics It is currently Sat Jul 21, 2018 12:57 pm



Reply to topic  [ 3 posts ] 
 spawning something and keeping track of it too (SOLVED: ez) 
Author Message

Joined: Mon Dec 21, 2015 9:30 am
Posts: 80
Reply with quote
Post spawning something and keeping track of it too (SOLVED: ez)
sfx = CreateAEmitter("Engine KPV-14");
sfx.Pos = self.Pos;
MovableMan:AddParticle(sfx);

there is some basic spawning code. i would like to have a pointer to this spawned item so i can control it within the same .lua file. can that be done?

EDIT: nvm! solved instantly via wild guessing.

here is how it works:

sfx = CreateAEmitter("Engine KPV-14");
sfx.Pos = self.Pos;
self.engineSound = ToAEmitter(sfx)
print(self.engineSound)
MovableMan:AddParticle(sfx);

the print will give the proper thing. the spawning works fine, no errors occur. self.engineSound becomes a pointer to that object. obviously change aemitter to the appropriate thing if you wanna use it


Sun Feb 04, 2018 1:17 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 649
Location: Halifax, Canada
Reply with quote
Post Re: spawning something and keeping track of it too (SOLVED: ez)
You probably shouldn't have to do that ToAEmitter there but whatever, CC's finicky so maybe you do.
You should use local variables though, with lua if you don't use the local keyword (or put them in self or some other table) your variables will be declared in the global namespace which is kinda messy.


Tue Feb 06, 2018 7:19 am
Profile

Joined: Mon Dec 21, 2015 9:30 am
Posts: 80
Reply with quote
Post Re: spawning something and keeping track of it too (SOLVED: ez)
Bad Boy wrote:
You probably shouldn't have to do that ToAEmitter there but whatever, CC's finicky so maybe you do.
You should use local variables though, with lua if you don't use the local keyword (or put them in self or some other table) your variables will be declared in the global namespace which is kinda messy.


if just sfx = self.enginesound or the other way around then for some reason sfx becomes nil and cant be spawned or controlled it's weird

also yeah i ended up doing self.x on everything once it started having issues with multiple of the same gun


Tue Feb 06, 2018 4:17 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

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.015s | 13 Queries | GZIP : Off ]