Graphics

 View Only
  • 1.  How to calculate square root in Xpression Visual Logic

    Posted 04-11-2018 21:50
    I need to calculate the square root of a number in Visual Logic, but there is no square root operator in the Xpression function blocks. Is there any way around this? My trigonometry is very rusty.


  • 2.  RE: How to calculate square root in Xpression Visual Logic

    Posted 04-12-2018 14:13
    I'm not sure if Visual Logic contains this block in its math functions as I'm not in front of an XPression currently, but you can always raise a number to a fractional exponent i.e. 16^(1/2) is the same as sqrt(16).
    #XPression


  • 3.  RE: How to calculate square root in Xpression Visual Logic

    Posted 04-12-2018 21:24
    There is no square root function block. I've looked and double checked.

    What function block would I use to raise a number to a power? I don't see anything there that seems to suggest that function....
    #XPression


  • 4.  RE: How to calculate square root in Xpression Visual Logic

    Posted 04-17-2018 23:15

    I think there's really no simple way to do it except fall back to scripting.

    Would be interesting to be able to define global functions that were callable from visual logic, but that's a pretty tall order.

    You could try setting a a hidden text object's text value to the number you want the square root of, and then use the onSetText function to convert to a float, find the square root, then do something like set the X-Position:

    Self.PosX = Math.sqrt(Cdbl(Text))

    Then you use the X position of the text object for the result of your square root. The caveat is that you might be a frame behind in your square root.



    EDIT: wanted to explain why converting to text and back - it was just so it would trigger the OnSetText function. You could it another way without having to do those conversions, like creating an OnRender script for the scene that takes a value from an object (like the X position), finds the square root, and sets the Y Position... I mean, there are a number of ways to hack it... none of the very pretty.


    #XPression


  • 5.  RE: How to calculate square root in Xpression Visual Logic

    Posted 04-18-2018 13:54
    Hi KatherineHollyDay,

    Squareroot in Visual Logic is available in XPression version 8.0.
    #XPression