How to create a new object instance in LUA.
Hello, I have something like this in my script: TPlayer= { nLife=100; nState=0; nCurrentWeapon=0; tbControls= TControl; } Now, I want to create 2 more instances of this table I have done this: a=TPlayer; b=TPlayer; but LUA only asigns the TPlayer reference to a and b (same object), how can I do that?. Thnaks in advance, HexDump.
There's no general method for copying a table, because it's not clear what exactly that entails. Are the contents copied or referenced? For instance, if table A had a reference to some other table, would that second table be copied too? Would its tables? Would closures be duplicated?
It looks like what you really want, more or less, is some way to generate these tables. I suggest you change your variable assignment into a function:
It looks like what you really want, more or less, is some way to generate these tables. I suggest you change your variable assignment into a function:
function makeTPlayer() return { nLife=100; nState=0; nCurrentWeapon=0; tbControls= TControl; }enda = makeTPlayer()b = makeTPlayer()
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement