Notifications
Clear all

[Closed] Undo – Script Controller error

 MZ1

When I delete some objects and do undo, multiple errors will pops ups and shows that node variable is not exist any more. this is an example of script controller with node variable:

Obj1 = box()
Obj2 = box pos:[30,30,30]
FS = float_script()
FS.addNode "Obj2" Obj2
FS.SetExpression "Obj2.pos.x"
Obj1.pos.controller[1].controller = FS

When I hit delete key on keyboard, then undo, errors will comes up.

5 Replies
3 Replies
(@denist)
Joined: 11 months ago

Posts: 0

in the expression you have to check that ‘obj2’ is a valid node and not deleted

 MZ1
(@mz1)
Joined: 11 months ago

Posts: 0

1 – do you think “isvalidnode” is OK for this?
2 – why this error is happening? Why is not happening when I delete object by code?
3 – do I had to check validation only for nodes? or for every variable inside controller?

(@denist)
Joined: 11 months ago

Posts: 0

let’s say we made a node and assign a variable:


b = box()


after that we delete b

if we check “isvalidnode b” it returns “false”
if we check “isdeleted b” it returns “true”

it’s hard manually check but it might be situation when a node is still valid but already marked as deleted.

so the safe way to check that a node is good to work with is:


isvalidnode <node> and not isdeleted <node>


how about this Mehdi

Obj1 = box()
Obj2 = box pos:[30,30,30]
FS = float_script()
FS.addNode "Obj2" Obj2
FS.addNode "Obj1" Obj1
FS.SetExpression "
inipos = Obj1.pos.x
if Obj2 != undefined then (Obj2.pos.x) else inipos "
Obj1.pos.controller[1].controller = FS

or even you can go further with adding a trash object and a script controller in its scale controller and try to remove the Obj1 script controller when the main object get delete or a #nodePreDelete callback .

 MZ1

I just created a function to add the validation for every expression:

fn SetExpression Controller OldStr =
(
Str = “Nodes = for n in #(”
NodeNamed = for i = 5 to Controller.NumVariables() where Controller.GetType i == #node collect Controller.GetName i
for i = 1 to NodeNamed.count do
(
if i != 1 do Str += “,”
Str += NodeNamed[i]
)
Str += “) where not isvalidnode n collect n

Str += “if Nodes.count == 0 then

Str += “(

Str += OldStr + “

Str += “)else 0

Controller.SetExpression Str
)