Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by flowen_nl · Jan 24, 2017 at 09:55 AM · functionstatic

global static function returns nullReference error [unityscript]

hi!

I have a _globals.js:

 public static class _globals
 {
     public static function _map(value, A, B, C, D) : float 
     {
         return (value - A) / (B - A) * (D - C) + C;
     }
 }


I assign the variables like this in otherScript.js

 var b = _globals._map(_brightness, 0, 1, 0, 5);


But it keeps giving my this error:

NullReferenceException: Object reference not set to an instance of an object Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) _globals._map (System.Object value, System.Object A, System.Object B, System.Object C, System.Object D) (at Assets/Scripts/_globals.js:11) animations.FixedUpdate () (at Assets/Scripts/animations.js:20)

I'm lost! what am I doing wrong here? From what I understood a static class doesn't need an instance. Alas I tried this as well:

_globals.js:

 public class _globals
 {
     function _map(value, A, B, C, D) : float 
     {
         return (value - A) / (B - A) * (D - C) + C;
     }
 }

 private var g = new _globals();
 g._map(blablalbal)


same error! It keeps referring to the _map function but I have no clue what's wrong there. Who can enlighten me?

ps: though I get an error It still gives me the right values and everything works correctly..

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by flowen_nl · Feb 01, 2017 at 04:57 PM

alright I sort of fixed the problem... I simply have to turn on the app that sends the OSC, so that the variable actually exists is my guess that fixes this problem o_O

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Landern · Jan 24, 2017 at 02:16 PM

I have zero problem with your static first version once i declared what each parameter to the _map function was, prior to that errors were displaying referencing using the '-' operator on type of Object.

 public static class _globals
  {
      public static function _map(value:float, A:float, B:float, C:float, D:float) : float 
      {
          return (value - A) / (B - A) * (D - C) + C;
      }
  }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flowen_nl · Jan 25, 2017 at 03:31 PM 0
Share

he man! thanks for checking, but I keep getting this error:

 NullReferenceException: Object reference not set to an instance of an object
 Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (IConvertible convertible)
 Boo.Lang.Runtime.RuntimeServices.CheckNumericPromotion (System.Object value)
 Boo.Lang.Runtime.RuntimeServices.UnboxSingle (System.Object value)
 animations.FixedUpdate () (at Assets/Scripts/animations.js:20)

copy pasted your code...

animations:20 is:

 var x = Globals._map(_pos, 0, 1, 0, 15);

and _pos is getting a public value from a different script (using oscReceiver script):

 _pos = oscScript.GetComponent.<oscReceiver>()._aa2;

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can the viewport rect of a camera be static? 0 Answers

Unexpected Symbol 'int' 1 Answer

How to get static speed 1 Answer

Highscore not working 0 Answers

When I call a function, It doesn't run completely 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges