Author Topic: .setMusic/.setSound being a bitch - Solved.  (Read 2525 times)

Cannot be achieved.
Yes it can? When using Daycycle Events, Environment Events and VCE you would just make a variable to the brick each time you change the skybox or sunflare or even the ground plate. Then, when the day-cycle hit its check (dawn, noon, etc) it will check that named brick for the current "skybox" variable, then you can change the music brick to whatever music you want for that variable

Daycycle events is broken and not even Lugnut can fix it.

Daycycle events is broken and not even Lugnut can fix it.
They work fine for me. Although I did clean a bit of the code up in the version that I have. You could easily make dayCycle events yourself using Ports resource http://forum.blockland.us/index.php?topic=241022.0

I never had any issues with Lugnuts, except that it takes a whole day (sim time) for the daycycle to sync in

You could easily make dayCycle events yourself
That is what I AM doing. THe problem here isn't the cycle. It's the setMusic/setSound.

*sigh*

Here are the events on the music brick


And the event on a separate brick that calls the checkWeather function. You could technically have this
on the music brick, but it's makes it less of a hassle this way.



You could also use VCE to randomize the weather each dawn, noon, etc

As you can see, it would take quite a few events depending on how many different environment themes you want. Obviously it would still be much easier to have an actual coded mod for this, but it is indeed possible with these events

Goth, you're going off-topic. I do not want an event nor to use other add-ons apart from the 2D brick.

Goth, you're going off-topic. I do not want an event nor to use other add-ons apart from the 2D brick.
I wasn't going off-topic, I was giving you a possible solution. You don't want to use any add-on other than the 2D music brick?

Good luck with your code. I would suggest defining $AmbienceBrick and making onHourChange a brick function

From the information I've read here I can only guess it's a formatting problem, because I find your formatting weird.

But it's far more likely to be a problem somewhere else, such as in the brick you're using, or another part of the add-on you are writing.
I suggest posting the entire add-on here, or sending it to the interested parties.  Including the brick you are using.

If you send it to me I will take a look at it to see if I can get it working.

From the information I've read here I can only guess it's a formatting problem, because I find your formatting weird.
Formatting doesn't matter in TorqueScript. It's just a matter or preference and readability. They're all just going off track about who has the better formatting, when it really doesn't matter.

If all else fails (jesus christ this topic is a trainwreck), take note of how music bricks work. Every time you change a normal music brick's music, an audioEmitter object attached to that brick is deleted and recreated.

https://github.com/TheBlackParrot/blockland-falling-platforms/blob/master/commands.cs#L152
Code: [Select]
$Platforms::Music = new AudioEmitter() {
is3D = 0;
profile = "musicData_FP" @ %which;
referenceDistance = 999999;
maxDistance = 999999;
volume = 1;
position = $loadOffset;
};

Truthfully, you don't even need a brick.

If need be, I can create a function real quick.

From the information I've read here I can only guess it's a formatting problem, because I find your formatting weird.

But it's far more likely to be a problem somewhere else, such as in the brick you're using, or another part of the add-on you are writing.
I suggest posting the entire add-on here, or sending it to the interested parties.  Including the brick you are using.

If you send it to me I will take a look at it to see if I can get it working.
Code: [Select]
$Pref::Survival::DayCycle::Length = 12;
$Pref::Survival::DayCycle::Precition = 2.5;
$EnvGUI::SimpleMode = 0;
setHourOfDay(12);

if(!isObject(musicData_Day)) warn("Day music datablock missing!");
if(!isObject(musicData_Night)) warn("Night music datablock missing!");
if(!isObject(musicData_Morning)) warn("Morning music datablock missing!");


function dayNightCycleLoop() {
if($Pref::Survival::DayCycle::doDayCycle) {
setHourOfDay($Survival::TimeOfDay + $Pref::Survival::DayCycle::Length/24/$Pref::Survival::DayCycle::Precition);
//echo("Doing tick!");
schedule($Pref::Survival::DayCycle::Length*1000*60/24/$Pref::Survival::DayCycle::Precition, 0, "dayNightCycleLoop");
}
}

function servercmdStartDayCycle(%client) {
//if(%client.isAdmin) {
$Pref::Survival::DayCycle::doDayCycle = true;
talk("Day cycle now running!");
dayNightCycleLoop();
//}
}

function foggyDays() {
$Pref::Survival::DayCycle::Disasters = 1.0;
}

function servercmdStopDayCycle(%client) {
//if(%client.isAdmin) { //give power to the people!
$Pref::Survival::DayCycle::doDayCycle = false;
talk("Day cycle stopped running!");
//}
}

function onHourChange(%hour) {
//Package it!
if(%hour == 6) {
if(!isObject($AmbienceBrick)) { warn("Ambience brick doesn't exist!"); return; }
$AmbienceBrick.setMusic("Morning");

} else if(%hour == 13) {
if(!isObject($AmbienceBrick)) { warn("Ambience brick doesn't exist!"); return; }
$AmbienceBrick.setMusic("Day");
} else if(%hour == 22) {
if(!isObject($AmbienceBrick)) { warn("Ambience brick doesn't exist!"); return; }
$AmbienceBrick.setMusic("Night");
}
}


function setHourOfDay(%hour) {
if(%hour > 23)
%hour = 0;
%actualHour = %hour;
$Survival::TimeOfDay = %hour;
if(%hour > 12) {
%hour = %hour-12;
%hour = 12-%hour;
}
setEnvironment("AmbientLightColor",0.35/12 * %hour + 0.6/12 SPC 0.35/12 * %hour + 0.6/12 SPC 0.35/12 * %hour + 0.6/12 SPC "1.000000");
setEnvironment("DirectLightColor",0.53/12 * %hour + 0/12 SPC 0.53/12 * %hour + 0/12 SPC 0.53/12 * %hour + 0/12 SPC "1.000000");
setEnvironment("FogColor",1/12 * %hour + 0/12 SPC 1/12 * %hour + 0/12 SPC 1/12 * %hour + 0/12 SPC 0/11 * %hour + 0/11);
setEnvironment("FogDistance",1000/2 * %hour + -10000/2);
setEnvironment("FogHeight","0");
setEnvironment("GroundColor","1.000000 1.000000 0.700000 1.000000");
setEnvironment("ShadowColor",0.4/12 * %hour + 0/12 SPC 0.4/12 * %hour + 0/12 SPC 0.4/12 * %hour + 0/12 SPC "1.000000");
setEnvironment("SkyColor",1/12 * %hour + 0/12 SPC 1/12 * %hour + 0/12 SPC 1/12 * %hour + 0/12 SPC "1.000000");
setEnvironment("Sunational socialistmuth","160");
setEnvironment("SunElevation",200/23 * %actualHour + -230/23);
setEnvironment("SunFlareColor",0.4/12 * %hour + 0/12 SPC 0.5/12 * %hour + 0/12 SPC 0.7/12 * %hour + 0/12 SPC "1.000000");
setEnvironment("SunFlareSize",1/12 * %hour + 0/12);
// setEnvironment("UnderWaterColor",139.4/12 * %hour + 7.2/12 SPC 177.3/12 * %hour + 8.4/12 SPC 254/12 * %hour + 12/12 SPC 133.5/12 * %hour + 6/12);
// setEnvironment("VignetteColor","0.000000 0.000000 0.000000 0.000000"); //Doesn't seem to exist.
setEnvironment("VisibleDistance",1000/-38 * %hour + -50000/-38);
// setEnvironment("WaterColor",139.4/12 * %hour + 7.2/12 SPC 177.3/12 * %hour + 8.4/12 SPC 254/12 * %hour + 12/12 SPC 133.5/12 * %hour + 6/12);
// setEnvironment("WaterHeight",0.3/12 * %hour + 36/12);
if(mFloor(%actualHour) == %actualHour) {
onHourChange(%actualHour);
}
}

function getEquation(%x1,%y1,%x2,%y2) {
echo(%y2 - %y1 @ "/" @ %x2 - %x1 @ " * %hour + " @ %x2*%y1 - %x1*%y2 @ "/" @ %x2 - %x1);
setClipboard(%y2 - %y1 @ "/" @ %x2 - %x1 @ " * %hour + " @ %x2*%y1 - %x1*%y2 @ "/" @ %x2 - %x1);
}
function exportHourEnvironmentSettings() {
%file = new FileObject();
%file.openForAppend("config/server/envSettings.cs");
%file.writeLine("setEnvironment(\"AmbientLightColor\",\"" @ $EnvGUI::AmbientLightColor @ "\");");
%file.writeLine("setEnvironment(\"DirectLightColor\",\""  @ $EnvGUIServer::DirectLightColor @ "\");");
%file.writeLine("setEnvironment(\"FogColor\",\""  @ $EnvGUIServer::FogColor @ "\");");
%file.writeLine("setEnvironment(\"FogDistance\",\""  @ $EnvGUIServer::FogDistance @ "\");");
%file.writeLine("setEnvironment(\"FogHeight\",\""  @ $EnvGUIServer::FogHeight @ "\");");
%file.writeLine("setEnvironment(\"GroundColor\",\""  @ $EnvGUIServer::GroundColor @ "\");");
%file.writeLine("setEnvironment(\"ShadowColor\",\""  @ $EnvGUIServer::ShadowColor @ "\");");
%file.writeLine("setEnvironment(\"SkyColor\",\""  @ $EnvGUIServer::SkyColor @ "\");");
%file.writeLine("setEnvironment(\"Sunational socialistmuth\",\""  @ $EnvGUIServer::Sunational socialistmuth @ "\");");
%file.writeLine("setEnvironment(\"SunElevation\",\""  @ $EnvGUIServer::SunElevation @ "\");");
%file.writeLine("setEnvironment(\"SunFlareColor\",\""  @ $EnvGUIServer::SunFlareColor @ "\");");
%file.writeLine("setEnvironment(\"SunFlareSize\",\""  @ $EnvGUIServer::SunFlareSize @ "\");");
%file.writeLine("setEnvironment(\"UnderWaterColor\",\""  @ $EnvGUIServer::UnderWaterColor @ "\");");
%file.writeLine("setEnvironment(\"VignetteColor\",\""  @ $EnvGUIServer::VignetteColor @ "\");");
%file.writeLine("setEnvironment(\"VisibleDistance\",\""  @ $EnvGUIServer::VisibleDistance @ "\");");
%file.writeLine("setEnvironment(\"WaterColor\",\""  @ $EnvGUIServer::WaterColor @ "\");");
%file.writeLine("setEnvironment(\"WaterHeight\",\""  @ $EnvGUIServer::WaterHeight @ "\");");
%file.close();
%file.delete();
}

//forget you
function setEnvironment(%varName, %value)
{
// if ($EnvGuiServer["::" @ %varName] $= %value)
// return;

switch$ (%varName)
{
case "SimpleMode":
$EnvGuiServer::SimpleMode = mClamp(%value, 0, 1);
EnvGuiServer::setSimpleMode();

if (!$EnvGuiServer::SimpleMode)
{
if (!$EnvGuiServer::HasSetAdvancedOnce)
EnvGuiServer::readAdvancedVarsFromSimple();

EnvGuiServer::setAdvancedMode();
}

case "SkyIdx":
$EnvGuiServer::SkyIdx = mClamp(%value, 0, $EnvGuiServer::SkyCount);
setSkyBox($EnvGuiServer::Sky[$EnvGuiServer::SkyIdx]);

case "WaterIdx":
$EnvGuiServer::WaterIdx = mClamp(%value, 0, $EnvGuiServer::WaterCount);
setWater($EnvGuiServer::Water[$EnvGuiServer::WaterIdx]);

case "GroundIdx":
$EnvGuiServer::GroundIdx = mClamp(%value, 0, $EnvGuiServer::GroundCount);
setGround($EnvGuiServer::Ground[$EnvGuiServer::GroundIdx]);

case "SunFlareTopIdx":
$EnvGuiServer::SunFlareTopIdx = mClamp(%value, 0, $EnvGuiServer::SunFlareCount);
%top = $EnvGuiServer::SunFlareTop[$EnvGuiServer::SunFlareTopIdx];
%bottom = $EnvGuiServer::SunFlareBottom[$EnvGuiServer::SunFlareBottomIdx];
SunLight.setFlareBitmaps(%top, %bottom);

case "SunFlareBottomIdx":
$EnvGuiServer::SunFlareBottomIdx = mClamp(%value, 0, $EnvGuiServer::SunFlareCount);
%top = $EnvGuiServer::SunFlareTop[$EnvGuiServer::SunFlareTopIdx];
%bottom = $EnvGuiServer::SunFlareBottom[$EnvGuiServer::SunFlareBottomIdx];
SunLight.setFlareBitmaps(%top, %bottom);

case "DayOffset":
$EnvGuiServer::DayOffset = mClampF(%value, 0, 1);
DayCycle.setDayOffset($EnvGuiServer::DayOffset);

case "DayLength":
$EnvGuiServer::DayLength = mClamp(%value, 0, 86400);
DayCycle.setDayLength($EnvGuiServer::DayLength);

case "DayCycleEnabled":
$EnvGuiServer::DayCycleEnabled = mClamp(%value, 0, 1);
DayCycle.setEnabled($EnvGuiServer::DayCycleEnabled);

case "DayCycleIdx":
$EnvGuiServer::DayCycleIdx = mClamp(%value, 0, $EnvGuiServer::DayCycleCount);
%dayCycle = $EnvGuiServer::DayCycle[$EnvGuiServer::DayCycleIdx];
echo("server setting daycycle to " @ %dayCycle);
loadDayCycle(%dayCycle);

case "Sunational socialistmuth":
$EnvGuiServer::Sunational socialistmuth = mClampF(%value, 0, 360);
Sun.azimuth = $EnvGuiServer::Sunational socialistmuth;
Sun.sendUpdate();

case "SunElevation":
$EnvGuiServer::SunElevation = mClampF(%value, -10, 190);
Sun.elevation = $EnvGuiServer::SunElevation;
Sun.sendUpdate();

case "DirectLightColor":
$EnvGuiServer::DirectLightColor = getColorF(%value);
Sun.color = $EnvGuiServer::DirectLightColor;
Sun.sendUpdate();

case "AmbientLightColor":
$EnvGuiServer::AmbientLightColor = getColorF(%value);
Sun.ambient = $EnvGuiServer::AmbientLightColor;
Sun.sendUpdate();

case "ShadowColor":
$EnvGuiServer::ShadowColor = getColorF(%value);
Sun.shadowColor = $EnvGuiServer::DirectLightColor;
Sun.sendUpdate();

case "SunFlareColor":
$EnvGuiServer::SunFlareColor = getColorF(%value);
SunLight.color = $EnvGuiServer::SunFlareColor;
SunLight.sendUpdate();

case "SunFlareSize":
$EnvGuiServer::SunFlareSize = mClampF(%value, 0, 10);
// Badspot, why not just SunLight.setFlareSize(...);?
SunLight.flareSize = $EnvGuiServer::SunFlareSize;
SunLight.sendUpdate();

case "SunFlareIdx":
$EnvGuiServer::SunFlareIdx = mClamp(%value, 0, $EnvGuiServer::SunFlareCount);
// ... what? Why does this exist? There is no "SunFlareIdx" system.
// Get outta' here.

case "VisibleDistance":
$EnvGuiServer::VisibleDistance = mClampF(%value, 0, 1000);
Sky.visibleDistance = $EnvGuiServer::VisibleDistance;
Sky.sendUpdate();

case "FogDistance":
$EnvGuiServer::FogDistance = mClampF(%value, 0, 1000);
Sky.fogDistance = $EnvGuiServer::FogDistance;
Sky.sendUpdate();

case "FogHeight":
$EnvGuiServer::FogHeight = mClampF(%value, 0, 1000);
// Nothing to see here...

case "FogColor":
$EnvGuiServer::FogColor = getColorF(%value);
Sky.fogColor = $EnvGuiServer::FogColor;
Sky.sendUpdate();

case "WaterColor":
$EnvGuiServer::WaterColor = getColorF(%value);

if (isObject(WaterPlane))
{
WaterPlane.color = getColorI($EnvGuiServer::WaterColor);
WaterPlane.blend = getWord(WaterPlane.color, 3) < 255;
WaterPlane.sendUpdate();
}

//updateWaterFog();

case "WaterHeight":
$EnvGuiServer::WaterHeight = mClampF(%value, 0, 100);

if (isObject(WaterPlane))
{
%pos = getWords(GroundPlane.getTransform(), 0, 2);
%pos = vectorAdd(%pos, "0 0" SPC $EnvGuiServer::WaterHeight);

WaterPlane.setTransform(%pos SPC "0 0 1 0");
WaterPlane.sendUpdate();

//updateWaterFog();

if (isObject(WaterZone))
{
%pos = vectorSub(%pos, "0 0 99.5");
%pos = vectorSub(%pos, "500000 -500000 0");
WaterZone.setTransform(%pos SPC "0 0 1 0");
}
}

case "UnderWaterColor":
$EnvGuiServer::UnderWaterColor = getColorF(%value);

if (isObject(WaterZone))
{
WaterZone.setWaterColor($EnvGuiServer::UnderWaterColor);
}

case "SkyColor":
$EnvGuiServer::SkyColor = getColorF(%value);
// Something is off about this one...
Sky.skyColor = $EnvGuiServer::SkyColor;
Sky.sendUpdate();

// Should probably combine this into one
// case "WaterScrollX" or "WaterScrollY":
case "WaterScrollX":
$EnvGuiServer::WaterScrollX = mClampF(%value, -10, 10);
$EnvGuiServer::WaterScrollY = mClampF($EnvGuiServer::WaterScrollY, -10, 10);

if (isObject(WaterPlane))
{
WaterPlane.scrollSpeed = $EnvGuiServer::WaterScrollX SPC $EnvGuiServer::WaterScrollY;
WaterPlane.sendUpdate();
}

if (isObject(WaterZone))
{
%fx = $EnvGuiServer::WaterScrollX * 414;
%fy = $EnvGuiServer::WaterScrollY * -414;

WaterZone.appliedForce = %fx SPC %fy SPC 0;
WaterZone.sendUpdate();
}

case "WaterScrollY":
$EnvGuiServer::WaterScrollY = mClampF(%value, -10, 10);
$EnvGuiServer::WaterScrollX = mClampF($EnvGuiServer::WaterScrollX, -10, 10);

if (isObject(WaterPlane))
{
WaterPlane.scrollSpeed = $EnvGuiServer::WaterScrollX SPC $EnvGuiServer::WaterScrollY;
WaterPlane.sendUpdate();
}

if (isObject(WaterZone))
{
%fx = $EnvGuiServer::WaterScrollX * 414;
%fy = $EnvGuiServer::WaterScrollY * -414;

WaterZone.appliedForce = %fx SPC %fy SPC 0;
WaterZone.sendUpdate();
}

case "GroundColor":
$EnvGuiServer::GroundColor = getColorF(%value);

if (isObject(GroundPlane))
{
GroundPlane.color = getColorI($EnvGuiServer::GroundColor);
GroundPlane.blend = getWord(GroundPlane.color, 3) < 255;
GroundPlane.sendUpdate();

Sky.renderBottomTexture = getWord(GroundPlane.color, 3) <= 0;
Sky.noRenderBans = Sky.renderBottomTexture;
Sky.sendUpdate();
}

case "GroundScrollX":
$EnvGuiServer::GroundScrollX = mClampF(%value, -10, 10);
$EnvGuiServer::GroundScrollY = mClampF($EnvGuiServer::GroundScrollY, -10, 10);

if (isObject(GroundPlane))
{
GroundPlane.scrollSpeed = $EnvGuiServer::GroundScrollX SPC $EnvGuiServer::GroundScrollY;
GroundPlane.sendUpdate();
}

case "GroundScrollY":
$EnvGuiServer::GroundScrollY = mClampF(%value, -10, 10);
$EnvGuiServer::GroundScrollX = mClampF($EnvGuiServer::GroundScrollX, -10, 10);

if (isObject(GroundPlane))
{
GroundPlane.scrollSpeed = $EnvGuiServer::GroundScrollX SPC $EnvGuiServer::GroundScrollY;
GroundPlane.sendUpdate();
}

case "VignetteMultiply":
$EnvGuiServer::VignetteMultiply = mClamp(%value, 0, 1);
sendVignetteAll();

case "VignetteColor":
$EnvGuiServer::VignetteColor = getColorF(%value);
sendVignetteAll();

default:
return 0;
}

return 1;
}//leetie <3

package AmbienceSoundPackage {

function fxDTSbrick::onPlant(%this) {
Parent::onPlant(%this);
if(%this.getName() $= "_Ambience_Brick" && %this.getDatablock().uiName $= "Music (Server-Wide)") {
$AmbienceBrick = %this;
}
}

function fxDTSbrick::onLoad(%this) {
Parent::onLoad(%this);
if(%this.getName() $= "_Ambience_Brick" && %this.getDatablock().uiName $= "Music (Server-Wide)") {
$AmbienceBrick = %this;
}
}

function fxDTSbrick::setName(%this,%anme) {
Parent::setName(%this,%anme);
if(%this.getName() $= "_Ambience_Brick" && %this.getDatablock().uiName $= "Music (Server-Wide)") {
$AmbienceBrick = %this;
}
}
};
activatePackage(AmbienceSoundPackage);

I've got this.

If all else fails (jesus christ this topic is a trainwreck), take note of how music bricks work. Every time you change a normal music brick's music, an audioEmitter object attached to that brick is deleted and recreated.

https://github.com/TheBlackParrot/blockland-falling-platforms/blob/master/commands.cs#L152
Code: [Select]
$Platforms::Music = new AudioEmitter() {
is3D = 0;
profile = "musicData_FP" @ %which;
referenceDistance = 999999;
maxDistance = 999999;
volume = 1;
position = $loadOffset;
};

Truthfully, you don't even need a brick.

If need be, I can create a function real quick.
I'll experiment with this during the weekend.

That formatting is a train wreck. Are you sure the function is even called?

You still haven't posted the code that creates these datablocks.

That formatting is a train wreck. Are you sure the function is even called?
Yes, it is called.

You still haven't posted the code that creates these datablocks.
The music datablock is made by Blockland when loading the server and the first three Ifs check if they exist. The brick datablock is made by Brick_2DMusic. I am nto sure which datablock you're talking about.

The music datablock is made by Blockland when loading the server

Why didn't you say that the first time

If you look at the music brick and say /getId, then manually call id.setSound(musicData_Day); does that work?