0 Favourites

How do I use the mathematical function "sign"

  • Hi there,

    anyone knowing if there is a possibility to use the "sign" function? It seems to be missing - is it missing or called differently?

    If missing, is there any workaround?

    ( I mean this: http://en.wikipedia.org/wiki/Sign_%28mathematics%29)

    It would be really, really useful <img src="{SMILIES_PATH}/icon_e_wink.gif" alt=";)" title="Wink">

    Thanks in advance!

  • [quote:22lbsloj]A real number is said to be positive if it is greater than zero, and negative if it is less than zero.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • What do you need it for ?

    Typically you would use System.Compare Variable with >0 or <0 instead.

  • If you are trying to use it in an expression somewhere, the workaround I've been using is to just have a variable that is always either -1 or 1. It makes the >0 or <0 check right before the expression. Of course this has limited application and doesn't really substitute a proper sign function...

  • define your own function which calculates the sign, you can call it in expressions with Function.Call("Sign", x)

  • The problem is, I need to be able to calculate like if sign(x) = sign(y) then A else B. And I like to be effektive, so trying to keep things short

    After Posting, I exactly figured the workaround of Zhon, that works well of course, since I only need the function for just one value.

    If I needed the function often in the script, I might use monitz87`s solution, though I am not sure how to do that in an effective way. I think that could become a bit complex, which makes it only worth to implement, if you need it all the time for a lot of different variables. Still a great solution, also I did not know at all, you could do that. So this Answer was very, very useful

    Thanks for the quick and helpful replies!

  • The problem is, I need to be able to calculate like if sign(x) = sign(y) then A else B. And I like to be effektive, so trying to keep things short

    After Posting, I exactly figured the workaround of Zhon, that works well of course, since I only need the function for just one value.

    If I needed the function often in the script, I might use monitz87`s solution, though I am not sure how to do that in an effective way. I think that could become a bit complex, which makes it only worth to implement, if you need it all the time for a lot of different variables. Still a great solution, also I did not know at all, you could do that. So this Answer was very, very useful

    Thanks for the quick and helpful replies!

    The bottom line is, whenever you are 'coding' in construct, there will be some times when you will think to yourself "god, how I wish I could just use javascript/python/C#/whateverlanguage and just tell the engine exactly what I want to do". AFAIK, the engine has a workaround for most of these cases. Scirra is working towards a Framework that will allow developers to never hit that hurdle, but in the meantime, you can stick with what you've got.

    As far as workarounds go, implementing your own sign expression as a Function is pretty straightforward, although I fully understand how just having sign(x) as a system expression would save you a lot of time

  • monitz87: I'm happy with Construct 2 completely, getting along awesome, though i NEVER wrote any code before... Also I am faster than most of my programming friends, so construct already saves you massive time, I get that.

    So no complains at all, at the end of the day, I just thought, let's ask people with more experience. And it was worth it, since I learned something new

    Thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,136
karshinkoff's avatar
karshinkoff
Unread hot topic
56 4,728
MPPlantOfficial's avatar
MPPlantOfficial
Unread hot topic
76 9,273
Pandadoor's avatar
Pandadoor