self.BaseClass.PhysicsSimulate(self) doesn't work

Hi, i’ve created a vehicle base which uses ENT:PhysicsSimulate() to move. The moving code is fine when used in a non-derived SEnt. However, when using this base i am trying to use self.BaseClass.PhysicsSimulate(self) to use this code. This does not work. I would have thought that since self.BaseClass.Initialize(self) works it would work for this as well. Is there something else i need?

[editline]04:37PM[/editline]

Also, I know it doesn’t work as i put:
[lua]print(“Physics Simulate has been called”)[/lua]
in the function and nothing

You also need to pass the arguments like so:
[lua]self.BaseClass:PhysicsSimulate(phys, deltatime)[/lua]

You need to call **[Entity.StartMotionController

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.StartMotionController)** in :Initialize()

Yeah it is in the base

[editline]05:18PM[/editline]

Thanks, but now i have another problem…





...rgate vehicles\lua\entities\sg_vehicle_base\init.lua:126: attempt to call method 'GetForward' (a nil value)



GetForward() is a valid function i use it alot. Why doesn’t it work here?

What are you using it on?

[lua]self.BaseClass.PhysicsSimulate( self, physObj, dt );[/lua]

You need to call the baseclass function like so. BaseClass isn’t an entity.

It’s in ENT:PhysicsSimulate(phys,deltatime).
[lua]local FWD = self:GetForward()[/lua]

Thats the line the error is coming from

It should be exactly the same. : Defines calls a function as a method, passing the table you’re calling the function on as self.

[lua]local mytable = {}

function mytable.Boobs(mytable , what)

end

function mytable:Boobs(what)

end

– they’re exactly the same.[/lua]



self.BaseClass:PhysicsSimulate( physObj, dt )


is the same as



self.BaseClass.PhysicsSimulate( self.BaseClass, physObj, dt )


But is not the same as



self.BaseClass.PhysicsSimulate( self, physObj, dt )


:colbert:

Should that not be:

[lua]function mytable.Boobs(self , what)

end[/lua]

Or am I missing something.

It doesn’t matter. self is just the default name when the function is defined with a colon. If you define it with a dot and call it with a colon, the first argument will be the object you called it on (durr:Boobs(something) would make mytable equal durr in the Boobs function.)

I’m just confusing you more ain’t I?:saddowns:

When you use the : operator to define the function, then call it, Lua automatically sets a local inside the function called “self” - not called “mytable”. You can still use mytable since it’s a global/upvalue of that function.

[lua]local MyTable = {}

function MyTable:Boobs( howbig )
// When this function is called like this:
// MyTable:Boobs( “over 9000” )
// Lua sets the “self” variable to be “MyTable”
end[/lua]

Or are you trying to explain something else?

It doesn’t matter what you call the first parameter, it’s still the same table.

[editline]01:40PM[/editline]

Defining it as a method will use self though.

I’m saying if you do.
[lua]
function MyTable:Boobs( howbig )
[/lua]
The object you call it on/the first var will be represented by self inside the function.
But if you do
[lua]
function MyTable.Boobs( abrakadabra, howbig )
[/lua]
The object you call it on/the first var will be represented by abrakadabra and not self.

I see. It’s just that’s not what your original code sample demonstrates.

Sorry, I’ll be more clear next time:v:

Get your Boobs off of MyTable.

howbig is your ‘MyTable’?:smug:

nil. Tom set it to a string and not a number. :smug:

Wait. That’s an infinite lo-