Data Realms Fan Forums
http://forums.datarealms.com/

spawning something and keeping track of it too (SOLVED: ez)
http://forums.datarealms.com/viewtopic.php?f=73&t=46243
Page 1 of 1

Author:  Hoovytaurus [ Sun Feb 04, 2018 1:17 am ]
Post subject:  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

Author:  Bad Boy [ Tue Feb 06, 2018 7:19 am ]
Post subject:  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.

Author:  Hoovytaurus [ Tue Feb 06, 2018 4:17 pm ]
Post subject:  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

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/