Blockland Forums > Modification Help
Changing The Sun's Ambience
jes00:
How would I change the sun's ambience through code?
Electrk:
--- Quote from: jes00 on December 27, 2011, 03:40:46 PM ---How would I change the sun's ambience through code?
--- End quote ---
This is a little code my friend helped me with while I was experimenting with stuff:
--- Code: ---function setSun(%color,%ambient) {
for(%i=0; %i<missiongroup.getCount(); %i++) { %obj=missiongroup.getObject(%i); if(%obj.getClassname()$= "Sun") %obj.delete(); }
$Sun = new sun(INSERT SUN NAME HERE) { color = %color; ambient = %ambient;}; //replace INSERT SUN NAME HERE with whatever you'd like to name your sun
}
--- End code ---
Then, all you need to do is call the function setSun with the color, like so:
--- Code: ---setSun("0.600000 0.600000 0.600000 1.000000","0.600000 0.600000 0.600000 1.000000"); //replace the colors with whatever you'd like. The first set of numbers is the sun's color, and the second set of numbers is the sun's ambient color.
--- End code ---
jes00:
I don't want to change the sun's color, only the ambience.
Superb:
Get the sun object, and echo(sun.ambient);
and just change it to your liking by doing sun.ambient = %ambient;
Amade:
--- Quote from: Superb on December 27, 2011, 07:30:41 PM ---Get the sun object, and echo(sun.ambient);
and just change it to your liking by doing sun.ambient = %ambient;
--- End quote ---
The sun doesn't update in realtime. It will have to be recreated as in Electrk's post.
The color can be preserved in this manner:
--- Code: ---for(%i = 0; %i < missionGroup.getCount(); %i++)
{
if((%obj = missionGroup.getObject(%i)).getClassName() $= "Sun")
{
%color = %obj.color;
break;
}
}
setSun(%color, %ambient);
--- End code ---