[Closed] Distinguishing if an object has a controller or not
Hi!
We are just picking up scripting and are currently working on our first script, which is still very basic!
Our basic script adds a Position List controller to a camera. A second Position_XYZ controller in it has a Noise_Float controller to simulate a shaky camera. We are now trying to find a way to distinguish if a selected camera has this controller already added to it or not, but couldn’t find a command that would allow us to do this.
This is the basic part of the script that needs that distinguishing.
on btnCreateHCam picked CameraSelect do
(
if CameraSelect != undefined do
(
CameraSelect.wirecolor = red
CameraHName = CameraSelect
btnCreateHCam.text = CameraSelect.name
--this is where the script needs to distinguish if a camera already has the
--controllers in it i mentioned before, preferably in a form such as if...then
)
)
Is there any solution to this, or would we need to script the entire section differently?
Thanks in advance!
for list controllers, you could take advantge of the “setName” & “getName” functions…
When you add a controller in the list, name it uniquely, then just check for the name afterwards whenever you want to know if the controller with the name is already there.
hope this helps
yes that definitely helps, thanks!
as soon as i get round this next annoying problem with the pickbutton I will apply that.
The basic idea behind this part was to get information from the picked object and pass it on to a button that is used later. The problem is that the script runs through this section without errors, applies the picked objects name to the button, but then leaves all variables undefined.
Guess I am probably missing something basic here
[size=2]
on btnPickOrbObj picked OrbObjSelect do
(
if OrbObjSelect != undefined do
(
OrbObj = OrbObjSelect
btnPickOrbObj.text = OrbObjSelect.name --name the pickbutton
OrbObjParent = "$"+OrbObj.name -- store the selected objects name as string
-- get the picked objects position, rotation, min and max values
OrbObjPos = OrbObj.pos
OrbObjRot = OrbObj.rotation
OrbObjMin = OrbObj.min
OrbObjMax = OrbObj.max
)
)
[/size]
I just noticed that every time I execute the script one additional line of the script is evaluated. Could that be due to me having misunderstood how the “if OrbObjSelect != undefined do” line works? So much to learn… !
Have just noticed that the error is being caused by the OrbObj, OrbObjParent, OrbObjPos etc. variables not having any values stored in them before the pickbutton is pressed.
I solved this temporarily by creating a dummy right at the beginning of the script, which data is stored in to all the variables mentioned above. This way the variables all have values in them before the pickbutton is pressed.
I am sure there is a more efficient/simple solution to this though, any ideas?
I could only guess that you’re not declaring your variable properly… as you’ve mention then your pickbutton handler isnt giving you any errors, but instead is producing undefined variables…
here’s a common way of doing it inside a rollout:
rollout test "test"
(
-- varible declarations
local OrbObjPos
local OrbObjRot
local OrbObjMin
local OrbObjMax
-- pickbutton
pickbutton btnPickOrbObj "pick"
-- pickbutton handler
on btnPickOrbObj picked OrbObjSelect do
(
if OrbObjSelect != undefined do
(
OrbObj = OrbObjSelect
btnPickOrbObj.text = OrbObjSelect.name --name the pickbutton
OrbObjParent = "$"+OrbObj.name -- store the selected objects name as string
-- get the picked objects position, rotation, min and max values
OrbObjPos = OrbObj.pos
OrbObjRot = OrbObj.rotation
OrbObjMin = OrbObj.min
OrbObjMax = OrbObj.max
)
)
)
basically, you’ll just need to decalre them first, somewhat telling the rollout that you’ll be using these variables. And its OK to declare them as empty undefined variables. If you didnt declare the variables locally first, it would only exist inside the pickbutton handler, which causes it to be undefined.
If you have time, you could try reading through the reference about Local and Global variable declarations.
hope this helps.