Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Tobias · May 25, 2010 at 07:37 AM · javascriptmysql

Problem with mysql between CS and JavaScript

Hello.

Ive got my CS mysqlscript running. Ive created a class

public class mysqlconn : MonoBehaviour {
    string Start () {
        string row = "";
                ........
                return row;
}

and a Javascript file:

var text = mysqlconn.Start();
GUI.Label (Rect (10, 10, 100, 20), text);

But the Javascript file tells me that mysqlconn is an uknown identifier. what is my problem? Isnt it possible to give the variable row to the javascript file?

Second question: Do these files need to be in the same folder and attached to the same object?

Thanks

Comment
Add comment · Show 1
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 Cyclops · May 26, 2010 at 02:51 PM 0
Share

@Tobias, your second question is addressed by @Extrakun's Answer - when you use two different languages in Unity, you have to work on compilation order. Does that mean you applied @SpikeX's Answer, and then found a second problem? Have you gotten it completely working, and how?

2 Replies

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

Answer by qJake · May 25, 2010 at 08:56 AM

You can't just use "mysqlconn" out of nowhere, you didn't instantiate an instance of it.

You need to do one of three things:

  • Either have a game object with your MySQL script on it, and then get a reference to the MySQL script off that game object and use that, OR
  • Make your MySQL class public (don't derive it from MonoBehaviour), and instantiate an instance of it before trying to use it (mysqlconn mysql = new mysqlconn();) (these are basic programming concepts), OR
  • Make the methods in your MySQL class static. I don't know how you've coded your class, so I can't say for certain whether or not this will work, but it may.

I recommend option 2.

Also, I wouldn't put the MySQL query inside of an OnGUI() function (which it appears you may have done), unless you want your database to get hammered and your game to run really slow.

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 Extrakun · May 25, 2010 at 08:48 AM

Javascript are complied first before C#, so you have to code that JavaScript snippet in C#, or change the compilation order so that your C# code will compile first. There are some folder where you can place your C# script so it will be complied first. Refer to the documentation here.

Comment
Add comment · Show 7 · 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 qJake · May 25, 2010 at 08:53 AM 0
Share

No, this isn't the problem at all.

avatar image duck ♦♦ · May 25, 2010 at 08:57 AM 0
Share

Why do you think this isn't the problem SpikeX?... looks like it to me. (although I always welcome being proven wrong!).

avatar image qJake · May 25, 2010 at 10:24 AM 0
Share

Unless there's some code that he didn't post, he's trying to access a method of a class that he didn't instantiate! Obviously that's not going to work. Script compilation order is completely irrelevant here.

avatar image Mike 3 · May 25, 2010 at 11:09 AM 0
Share

Both of you are right. If they're in the same folder, he won't be able to use the type from JavaScript. But using the class name for an instance method isn't going to work either.

avatar image Cyclops · May 25, 2010 at 03:08 PM 0
Share

I wanted to upvote this answer, as it's true, the OP probably has two problems - instance not created, and wrong compilation order. But - this Answer says, "you have to code your JS in C#", which is incorrect. It's then followed by a link on how to fix compilation-order, which is why the first part is incorrect. A bit confusing, maybe you need to make it more clear that the problem and fix, is changing the order of script compilation. Not re-writing code.

Show more comments

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

No one has followed this question yet.

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Help with my double jump script 1 Answer

Physics: Is it possible to count the number of colliders hit with OverlapSphere? 1 Answer


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