"painted" isn't the material.
There are individual materials for the skybox.
"up", "dn", "lf", "rt", "bk", "ft"
For example:
lua_run_cl print(Material("painted"))
Material [___error]
But...
lua_run_cl print(Material("skybox/paintedup"))
Material [skybox/paintedup]
so you would need..
Material("skybox/paintedup")
Material("skybox/painteddn")
Material("skybox/paintedlf")
Material("skybox/paintedrt")
Material("skybox/paintedbk")
Material("skybox/paintedft")
Not sure if the rest of your code will work as I didn't try it.. but that should help you get started.