[code]for k = 0,ent:GetPhysicsObjectCount() do
[b]ent:GetPhysicsObjectNum( k ).pid = k[/b]
end[/code]
The bold code above ([b]ent:GetPhysicsObjectNum( k ).pid = k[/b]) is what causes this error: Attempt to access a userdata value
GetPhysicsObjectNum returns a physics object, not a table?
It returns a physics object according to the wiki and according to print()
So he's saying you can't set variables on a PhysObj, it has to be a table (I think).
Also PhysObjNums start at 1, not zero, so it's possible you're trying to set a table variable on a nil value which doesn't work well.
You sure it starts at 1? The wiki says it starts at 0, and I tested using 0. Also, you can set values on other structures, so I don't get why not on physobj, unless you are saying you can't set variables on just PhysObj?
Ah, well I might be mistaken about the 1 vs 0 thing.
But I would be careful about PhysObj, as they seem to be unworkable sometimes. Just try this for me in console and we can test it out (on a listen or SP server):
[code]lua_run Entity(1):GetPhysicsObjectNum(1).TestVar = 1
lua_run print( Entity(1):GetPhysicsObjectNum(1).TestVar )[/code]
[code]00:49:50 > ents.FindByClass("prop_physics")[1]:GetPhysicsObject().FAKEVAR = 1...
00:49:50 L 01/08/2010 - 00:49:51: Lua Error: :1: attempt to index a userdata value
00:49:51 :1: attempt to index a userdata value[/code]
Use ent.var instead.
Sorry, you need to Log In to post a reply to this thread.