83
« on: January 09, 2017, 12:54:39 AM »
Practically got me tearing my hair out, gonna post and then go to bed.
So. This package
package KeiCarRacing_EngineSounds
{
function armor::onMount(%this,%obj,%col)
{
Parent::onMount(%this,%obj,%col);
if (!isObject(%col) || %obj.getMountNode() != 0)
return;
echo(%col.getDataBlock().vehicleSounds);
if (%col.getDataBlock().vehicleSounds) {
%col.playAudio(0, KeiCarRacing_StartupSound);
schedule(1800, 0, KeiCarRacingSpeedCheck, %this, %col);
}
}
function armor::onUnMount(%this,%obj,%col)
{
Parent::onUnMount(%this,%obj,%col);
if (%obj.getMountNode() != 0)
return;
if (%col.getDataBlock().vehicleSounds) {
cancel(1);
%col.playAudio(0, KeiCarRacing_ShutOffSound);
}
}
};
ActivatePackage(KeiCarRacing_EngineSounds);
Does not work how I want it to (and I'm not sure why). Specifically, the cancel in the second function. This cancel is called on a schedule in the KeiCarRacingSpeedCheck function to cancel out the schedule at the end:
function KeiCarRacingSpeedCheck(%this, %obj)
{
if(!isObject(%obj))
return;
%vehicle = %obj;
%slot = 0; //Play the sound in the driver's spot
%speed = vectorLen(%obj.getVelocity());
if(%speed < 4)
%vehicle.playAudio(%slot, KeiCarRacing_IdleSound);
else// if (%speed < 20)
%vehicle.playAudio(%slot, KeiCarRacing_ThrottleSound);
schedule(500, 1, KeiCarRacingSpeedCheck, %this, %obj);
}
Whats happening is as follows:
I enter the car, and the audio for the startup sound is played. The KeiCarRacingSpeedCheck function then kicks in and plays the current sound corresponding with the speed. However, with the cancel, that schedule is apparently ended right away. The speed doesn't update if I'm going as fast as possible.
I also know that it cancels it because if I comment it out, once I get in the car, it makes noises until I break the brick.
Can someone point out my mistake?
Should I (can I?) just be using states for this?
Also as a total side note, for whatever reason, if I change the "armor" name(space?) of the two functions to something else, they won't execute. The framework for this code was ripped from Filipe's SuperKart mod and subsequently has the same name as one of the functions in Support_HandsOnVehicle. Activating my KeiCarRacing_EngineSounds also causes the player to stand inside the vehicle instead of sitting. If anyone has an answer as to why they won't execute and the player stands I would love that as well.
Honestly I am incredibly new to TS so if there is something glaringly horrible that I'm doing please let me know! Thanks for whatever help I can get!
Tags: Cancelling, function, car sounds, sounds