• self.BaseClass.PhysicsSimulate(self) doesn't work
    18 replies, posted
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 [b][url=http://wiki.garrysmod.com/?title=Entity.StartMotionController]Entity.StartMotionController [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] in :Initialize()
[QUOTE=ralle105;23230486]You need to call [b][url=http://wiki.garrysmod.com/?title=Entity.StartMotionController]Entity.StartMotionController [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] in :Initialize()[/QUOTE] Yeah it is in the base [editline]05:18PM[/editline] [QUOTE=DarKSunrise;23230122]You also need to pass the arguments like so: [lua]self.BaseClass:PhysicsSimulate(phys, deltatime)[/lua][/QUOTE] Thanks, but now i have another problem... [code] ...rgate vehicles\lua\entities\sg_vehicle_base\init.lua:126: attempt to call method 'GetForward' (a nil value) [/code] GetForward() is a valid function i use it alot. Why doesn't it work here?
[QUOTE=Ronon Dex;23230542]Yeah it is in the base [editline]05:18PM[/editline] Thanks, but now i have another problem... [code] ...rgate vehicles\lua\entities\sg_vehicle_base\init.lua:126: attempt to call method 'GetForward' (a nil value) [/code]GetForward() is a valid function i use it alot. Why doesn't it work here?[/QUOTE] 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.
[QUOTE=Dr Magnusson;23233363]What are you using it on?[/QUOTE] It's in ENT:PhysicsSimulate(phys,deltatime). [lua]local FWD = self:GetForward()[/lua] Thats the line the error is coming from
[QUOTE=Nevec;23233438][lua]self.BaseClass.PhysicsSimulate( self, physObj, dt );[/lua] You need to call the baseclass function like so. BaseClass isn't an entity.[/QUOTE] It [b]should[/b] 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]
[QUOTE=|FlapJack|;23248245]It [b]should[/b] 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][/QUOTE] [code] self.BaseClass:PhysicsSimulate( physObj, dt ) [/code] is the same as [code] self.BaseClass.PhysicsSimulate( self.BaseClass, physObj, dt ) [/code] But is not the same as [code] self.BaseClass.PhysicsSimulate( self, physObj, dt ) [/code] :colbert:
[QUOTE=|FlapJack|;23248245]It [b]should[/b] 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][/QUOTE] Should that not be: [lua]function mytable.Boobs(self , what) end[/lua] Or am I missing something.
[QUOTE=thomasfn;23258915]Should that not be: [lua]function mytable.Boobs(self , what) end[/lua] Or am I missing something.[/QUOTE] 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:
[QUOTE=ralle105;23260111]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:[/QUOTE] 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.
[QUOTE=thomasfn;23273304]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?[/QUOTE] 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.
[QUOTE=ralle105;23273973]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.[/QUOTE] 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: [QUOTE=thomasfn;23273304][lua]local MyTable = {} function MyTable:Boobs( howbig ) self:Boobs( "over 9000" ) end[/lua][/QUOTE] Wait. That's an infinite lo-
Sorry, you need to Log In to post a reply to this thread.