TOUR
PRICING
HELP
Stencylpedia
Blocks Guide
Sample Games
Developer Center
FORUMS
CHAT
#MADEINSTENCYL
EDUCATION
SIGN IN
×
Welcome back!
Username or E-mail
Password
(
Forgot?
)
C
OMMUNITY
Home
Issue Tracker
Inbox [0]
New Posts
New Replies
Search
Stencyl Community
→
Stencyl
→
Ask a Question
→
sign math block?
Pages:
1
sign math block?
Shadowblitz16
Posts: 44
August 06, 2015, 06:14:10 pm
how can i sign something for example...
sign(-12) = -1
sign(35) = 1
sign(0) = 0
sign(99999999999999999) = 1
sign(-99999999999999999) = -1
Hectate
Posts: 4643
August 06, 2015, 07:48:44 pm
If you have non-zero numbers, you can divide the number by it's own absolute value to get the sign. Division is clunky though, and if you just create your own custom block (function) you can easily use If/Else statements to do this.
Additionally, doing so would let you decide what to do with zeros, instead of dividing by zero and crashing.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.
Shadowblitz16
Posts: 44
August 06, 2015, 08:35:32 pm
i'm not sure how custom blocks work though :/
tomtomtom
Posts: 22
August 07, 2015, 02:54:07 am
Just create 2 number attributes: one for your number to be checked (CheckSign), one for your Sign-check (SignOutput)
If CheckSign is > 0
Set SignOutput to 1
If CheckSign = 0
Set SignOutput to 0
If CheckSign < 0
Set SignOutput to -1
Pages:
1