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



Reply to topic  [ 11 posts ] 
 Field variables 
Author Message
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post Re: Field variables
no part.Pos?


Sat Jun 19, 2010 2:34 pm
Profile WWW
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post Re: Field variables
Guess I will go with goldcost then.


Sat Jun 19, 2010 7:53 pm
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post 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!!


Mon Jun 21, 2010 4:17 am
Profile
User avatar

Joined: Sun Jul 13, 2008 9:57 am
Posts: 4886
Location: some compy
Reply with quote
Post 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
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.046s | 13 Queries | GZIP : Off ]