Page 1 of 1
Overriding setPitch
Posted: Fri Feb 06, 2015 5:38 pm
by dizzykiwi3
This probably has a simple solution but I'm a bit unfamiliar with Lua
How would I go about overriding the setPitch function so that I can have it link to a speed value so that it ramps down during slow-motion moments
The way I'm currently trying to do it is
Code: Select all
rampspeed = .1
origsetPitch = Source:setPitch
function Source:setPitch(pitch)
origsetPitch(pitch * rampspeed)
end
but that isn't working.
Re: Overriding setPitch
Posted: Fri Feb 06, 2015 5:48 pm
by slime
You could make a completely new function which does what you want, and change your game's code to call the new function instead of Source:setPitch directly. It would also have the added benefit of letting you use Source:setPitch directly in specific cases if you want.
Like this:
Code: Select all
rampspeed = 0.1
function SetRampingPitch(source, pitch)
source:setPitch(pitch * rampspeed)
end
Re: Overriding setPitch
Posted: Fri Feb 06, 2015 6:47 pm
by dizzykiwi3
I was thinking about doing that, it'd just save me some time if I could override it.
I'm also a bit unfamiliar with using the color and self parameters in lua functions so I wanted to try it out
is this syntax close to correct? It isn't working but I think it's close?
Code: Select all
origsetPitch = setPitch
function Source:setPitch(pitch)
self:origsetPitch(pitch * .1)
end
Re: Overriding setPitch
Posted: Tue Feb 10, 2015 4:27 pm
by BruceTheGoose
The self variable refers to the table used to call the method.
Code: Select all
Player = {}
Player.x = 0
function Player:move(x,dt)
self.x = self.x + x * dt
end
function Player:update(dt)
self:move(5,dt)
end