Data Realms Fan Forums
http://45.55.195.193/

Field variables
http://45.55.195.193/viewtopic.php?f=73&t=19028
Page 1 of 1

Author:  findude [ Sat Jun 19, 2010 1:34 pm ]
Post subject:  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?

Author:  Geti [ Sat Jun 19, 2010 2:34 pm ]
Post subject:  Re: Field variables

no part.Pos?

Author:  findude [ Sat Jun 19, 2010 3:50 pm ]
Post subject:  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.

Author:  Grif [ Sat Jun 19, 2010 7:10 pm ]
Post subject:  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)

Author:  Daman [ Sat Jun 19, 2010 7:19 pm ]
Post subject:  Re: Field variables

if you want a variable to act as a property of an object then you should use metatables

Author:  findude [ Sat Jun 19, 2010 7:53 pm ]
Post subject:  Re: Field variables

Guess I will go with goldcost then.

Author:  none [ Sun Jun 20, 2010 5:27 pm ]
Post subject:  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??

Author:  findude [ Sun Jun 20, 2010 5:30 pm ]
Post subject:  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.

Author:  Abdul Alhazred [ Sun Jun 20, 2010 5:40 pm ]
Post subject:  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?

Author:  Daman [ Mon Jun 21, 2010 4:17 am ]
Post subject:  Re: Field variables

http://lua-users.org/wiki/LuaClassesWithMetatable

lmao 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!!

Author:  Geti [ Mon Jun 21, 2010 4:55 am ]
Post subject:  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.

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