Search Unity

Javascript error - does not denote valid type

Discussion in 'Scripting' started by pixelthis, Sep 3, 2009.

  1. pixelthis

    pixelthis

    Joined:
    Nov 5, 2008
    Posts:
    120
    Hi all,

    We have a javascript file with the following line:
    Code (csharp):
    1. Bonjour.startLookup(service,"local");
    We have a C# script called 'Bonjour' in the 'scripts' folder, it contains the class:
    Code (csharp):
    1. public class Bonjour{....
    We get the error 'the name Bonjour does not denote a valid type'.

    However - if we have a C# script which tries to access Bonjour.startLookup, this works fine?

    Any ideas we we can't access 'Bonjour' from javascript but we can from C#?
     
  2. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
  3. DrHotbunz

    DrHotbunz

    Joined:
    Feb 14, 2009
    Posts:
    315
    Or to explain it in more detail:

    if your js script needs to reference a cs script and your getting an error "does not denote valid type".

    Then move your cs script to the Standard Assets folder and you wont get the error anymore.

    Slightly screwy solution but hey it works.
     
    julrulez likes this.
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The doc page Matthew linked to actually explains it in more detail, including why putting a script in Standard Assets works the way it does, and how you can avoid having to put C# scripts in Standard Assets in some cases, by using GetComponent and dynamic typing in Javascript.

    --Eric
     
  5. DDelapena

    DDelapena

    Joined:
    May 3, 2013
    Posts:
    6
  6. Mixxit

    Mixxit

    Joined:
    Aug 28, 2013
    Posts:
    33
    page is missing
     
  7. praleadanut

    praleadanut

    Joined:
    Feb 18, 2014
    Posts:
    2
    yoooou are the best !!!! :d
     
  8. Deleted User

    Deleted User

    Guest

  9. kiko-allouache

    kiko-allouache

    Joined:
    May 2, 2017
    Posts:
    4
    what about JAVAscript?
     
  10. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    UnityScript used to be called "JavaScript" due to an impressive amount of shortsightedness on Unity's side. It's still referred to as "JavaScript" in a bunch of places, but they're getting better at it now.
     
  11. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Let's be honest: It was named "JavaScript" to dupe people who'd done web development into buying Unity. The name JavaScript is a marketing lie and nothing more. And I'm not willing to use the past tense on that because it's still not referred to as UnityScript in any marketing materials at all - only in documentation. So they're still duping web developers with the name.
     
  12. skauth

    skauth

    Joined:
    Jun 4, 2017
    Posts:
    17
    Agreed. Still duping web developers. I am a web developer. It's easier to learn UnityScript than to try downloading/installing the Android Studios, and Unity is free too, so here I am. At least I have the aptitude for learning new languages. By the way, it's still called Javascript when you go to create a new script.

    Though the more UnityScript I learn, the more it seems like it would be easiest to just switch over to C# entirely. UnityScript is the hellspawn of C#, JS, and Satan. Nothing I like about JS (which is also included in PHP) is there. There's no loose typing. There's no dynamically created indexed arrays Well there is, but it's broken. If you try to access param1.minimum you get an error unless you specified that param1 could have a minimum. So you have to typecast everything anyways, even if you typecast it as a JavaScript Object. And then the syntax for typecasting is totally different from every other forced-OOP language. Typecasting upon declaration requires even more repeated words than forced-OOP languages. All the namespaced functions I'm used to, like Math.min(), Date.now(), etc. are gone. Wiped off the map. Replaced with the same namespaced functions I'd be using in C#, like Mathf.

    But it makes sense that they can't possibly let you use JS in the same way they let you use C#. Although loose typing is wonderful, it doesn't play too well with strict typing. And it would have to be compiled an entirely different way. UnityScript, as far as I'm aware, compiles to the same exact code that C# compiles to. So I'll be switching over to C# (I only have 4 scripts as part of the 2D Roguelike tutorial so far). To think! I found C# intimidating. I think UnityScript does have one benefit from being called JavaScript. People are more willing to try it, even if it completely shreds their hopes and dreams for a few days (or weeks, depending on how fast they pick up on the fact that it's different). I think C# could stand to have some more readable documentation. It shouldn't be intimidating. But it is intimidating.

    On a side note, I didn't realize you could buy Unity. I mean, I guess I did see something about fees, but that's only for large companies that could probably hire more than a web developer, right?
     
  13. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    It's a requirement to pay for one of the subscriptions if you earn enough. The cutoff is quite high, if you make over $100k a year you have to go with the $35 a month plan. There's some benefits to paying too, but nothing on what you can do with the engine. See here for details.
     
  14. MetaDataKor

    MetaDataKor

    Joined:
    Jun 2, 2017
    Posts:
    1
    I don't think mine works that way. Standard Assets folder in the Assets folder doesn't seem to help. It didn't exist, so I made it, corrected typos, added blank, and I am still getting the same Error. Any guesses?
     
  15. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
  16. Honorsoft

    Honorsoft

    Joined:
    Oct 31, 2016
    Posts:
    81
    Another solution that doesn't require moving anything around is to use an
    Code (CSharp):
    1. import
    at the top of the javascript (the same thing as C#'s "using"), such as
    Code (CSharp):
    1. import UnityStandardAssets.ImageEffects;
    or
    Code (CSharp):
    1. import UnityEngine;
    .