|
Hello. Ive got my CS mysqlscript running. Ive created a class
and a Javascript file:
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
(comments are locked)
|
|
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:
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.
(comments are locked)
|
|
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. No, this isn't the problem at all.
May 25 '10 at 08:53 AM
qJake
Why do you think this isn't the problem SpikeX?... looks like it to me. (although I always welcome being proven wrong!).
May 25 '10 at 08:57 AM
duck ♦♦
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.
May 25 '10 at 10:24 AM
qJake
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.
May 25 '10 at 11:09 AM
Mike 3
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.
May 25 '10 at 03:08 PM
Cyclops
(comments are locked)
|

@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?