[Closed] Setting up scripts as importable OR executable
My brain is fried right now so my manual searching skills are failing me.
Is there a way to set up a script to have a “main” function that only gets called if you run the script independantly?
I want to be able to have a script that can be included in another script, yet have a function that is only called when I run it by itself.
The closest example to what I mean is like the if name = “main” statement in python.
It’s probably obvious, but I can’t see it!
check if the function exists in a struct, if not, evaluate the main code.
fn test inScript:testStruct.test() =
(
if inScript != undefined then
(
print “shared”
)
else
(
Print “unique”
)
)
edit: even just check if the struct is declared, maybe? and not undefined. I dont know if its possible to detect if a script/function is in local or world space, other than seeing if it exists.
Edit 2: also you could just see if it can find a variable declared to it:
(
local foo = 100
fn test =
(
if foo != undefined then
(
)
else
(
)
)
This way if its contained with in a script, it can use that local variable of that script, it would be probably better to reference a variable in a instances struct, but then your’ll get scope problems.
Thanks Charles!
Hey, are you over at tech-artists.org ? I didn’t see your handle there.