Notifications
Clear all

[Closed] noob question: constructing float_expressions

I’m going in circles on this one. Would someone demonstrate how to put an expression controller together, please?

I’ve been trying to get a variable to change according to the relative positions of two objects. Currently playing with the idea of using a float_expression or float_script… don’t know if this is even a viable approach. But it turns out that’s begging the question; I can’t even figure out how to properly construct an expression controller, despite poring over all the Reference stuff I’ve got. When I try (don’t laugh)…

)
b1 = box()
b2 = box pos:[50,0,0]
local a = 1
fx = b1.position.controller = float_expression
fx.SetExpression = "if (b1.pos.y > b2.pos.y) then v = 2 else v = 1"
)

I get Unknown property: “SetExpression” in Controller:Float_Expression. Any guidance would be greatly appreciated. Thanks.

2 Replies

setExpression is a function, not a variable, you can not “assign” it value, you have to pass it…

fx.SetExpression "if (b1.pos.y > b2.pos.y) then v = 2 else v = 1"

Thanks, Rusty. Actually, I also screwed up the variable; it started out as “a”, then mysteriously switched to “v”.

When I run…

(
b1 = box()
b2 = box pos:[50,0,0]
local a = 1
fx = b1.position.controller.y_position.controller = float_expression()
fx.setExpression "if (b1.pos.y > b2.pos.y) then a=2 else 1=1"
)

…I get…

-- Runtime error: IExprCtrl::SetExpression - Expression parse error: if (b1