[Closed] Controlling Daylight System with MAXscript
Hi everyone
I’m just starting to learn MAXScript, and I know the basics, but I would like to figure out how to change a Daylight system that I have manually created using a script.
Based on this documentation, I’ve put together the following code:
$Daylight01.controller
Controller:Sunlight_Daylight_Slave_Controller
<Daylight_Slave_Controller>.solar_time Float
fn TimeFromSolarTime solar_time =
(
hrs = int(solar_time/3600.0) -- full hours in the solar_time value
min = int((solar_time - hrs*3600.0)/60.0) -- full minutes in the difference between the full time and the full hours
sec = int(solar_time - hrs*3600.0 - min*60.0 + 0.5) -- full seconds in the rest of the value
#(hrs,min,sec) -- return the result as a 3 elements array
)
I’m not exactly sure where to insert the actual desired time value (I’ve tried a few places). In any case, when I select the code and press Enter to run it, I get the following error:
Controller:Sunlight_Daylight_Slave_Controller
-- Error occurred in anonymous codeblock; filename: C:\Users\Jeremy\Documents\Modeling and Design\3dsMAX\scripts\lightcalc.ms; position: 37
-- Syntax error: at keyword parameter, expected <factor>
-- In line: Controller:S
There is precious little documentation on this, so I would appreciate the help!
The first three lines arent actually needed.
If you have created the sunlight system, you need to call the function like so:
TimeFromSolarTime(300.0)
I take it you are starting out with max so i’ll explain it a bit.
“fn” means you’re starting a new function. after that comes the function name followed by any paramaters you want to pass to the function. The function code is the bit between the brackets. You need to define the function before calling it (otherwise it doesnt exist yet). so in the example below it does just that.
If the function needs paramaters, you must specify what they are by putting it in the brackets. the example passes 300.0
fn TimeFromSolarTime solar_time =
(
hrs = int(solar_time/3600.0) -- full hours in the solar_time value
min = int((solar_time - hrs*3600.0)/60.0) -- full minutes in the difference between the full time and the full hours
sec = int(solar_time - hrs*3600.0 - min*60.0 + 0.5) -- full seconds in the rest of the value
solar_array = #(hrs,min,sec) -- return the result as a 3 elements array
return(solar_array)
)
TimeFromSolarTime(300.0)
print solar_array
now it loads and returns and array with 3 values called solar_array.
to access the individual values you do it like this:
solar_array[1] –hrs
solar_array[2] –min
solar_array[3] –sec