Author |
Message |
findude
Joined: Tue Dec 12, 2006 3:10 pm Posts: 495 Location: Uncertain quantum state
|
Field variables
Code: print(self.var) local part part = CreateMOPixel("particle"); MovableMan:AddParticle(part); part.var = self.var+1 print(part.var)
prints 1, 2, like it should However the particle that I created still has self.var as nil Is there a workaround to this? Am I doing something wrong?
|
Sat Jun 19, 2010 1:34 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Field variables
no part.Pos?
|
Sat Jun 19, 2010 2:34 pm |
|
|
findude
Joined: Tue Dec 12, 2006 3:10 pm Posts: 495 Location: Uncertain quantum state
|
Re: Field variables
Why would that matter? It was in the original script, but has no meaning here. Instead it would just spawn in the scene origin with this one.
|
Sat Jun 19, 2010 3:50 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Field variables
because you can't read or write self variables from an external script unless they're the specific lua properties (mass, etc)
"part.var" is probably just being created as a new global variable
try putting print(part.var) somewhere else in your script (after that bit runs)
|
Sat Jun 19, 2010 7:10 pm |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
Re: Field variables
if you want a variable to act as a property of an object then you should use metatables
|
Sat Jun 19, 2010 7:19 pm |
|
|
findude
Joined: Tue Dec 12, 2006 3:10 pm Posts: 495 Location: Uncertain quantum state
|
Re: Field variables
Guess I will go with goldcost then.
|
Sat Jun 19, 2010 7:53 pm |
|
|
none
Joined: Fri Dec 18, 2009 11:00 pm Posts: 167
|
Re: Field variables
perhaps self.var need to be defined as a number
like "self.var = 0"
Please correct me if I am wrong but isn't "nil" a string value??
|
Sun Jun 20, 2010 5:27 pm |
|
|
findude
Joined: Tue Dec 12, 2006 3:10 pm Posts: 495 Location: Uncertain quantum state
|
Re: Field variables
Obiviously self.var has been initialized.
"nil" means the variable has not been assinged any value; numeric, string, boolean or any other datatype.
Which I did. But it didn't work.
Hence this thread.
|
Sun Jun 20, 2010 5:30 pm |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
Re: Field variables
Daman wrote: if you want a variable to act as a property of an object then you should use metatables This sounds very interesting. I thought lua code could not change the metatables of userdata. Maybe you could you explain how to do this?
|
Sun Jun 20, 2010 5:40 pm |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
Re: Field variables
http://lua-users.org/wiki/LuaClassesWithMetatablelmao data should just give the source to me because whatever swede he has working on it doesn't know how to implement lua for ♥♥♥♥ There's no global metatable index, p much everything has something wrong with it. prints should not be prefixed with PRINT: that is dumb hey. i know guys. lets just store everything as completely inaccessible static objects. there u go!!
|
Mon Jun 21, 2010 4:17 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Field variables
Oh yeah, could you also use a hashed global table? Like, insert the variable into _globaltable[particlepointer] and then get whatever particle particlepointer is pointing to to grab it from _globaltable[self]? I'm not sure if this works in CC, I haven't been able to tinker in a while.
|
Mon Jun 21, 2010 4:55 am |
|
|
|