How to Pass a static var in Javascript value into a c# or download mysql text data using c#

Question :

I’m looking to either:
How to Pass a static var in Javascript value into a c# or download mysql text data using c#?


If I simply want to take the value inside of a STATIC VAR XX (where XX is my variable (will be full of Paragraphs of text) IN A JAVASCRIPT - and then Use a C# SCRIPT to Dsiplay that variable, How do I do that? Again - just trying to assign a JavaScripts Variable (for example ‘XX’) and transfer that value over to a CS Script - how would the C-Sharp script look?

Another way would be to simply download text from the MySQL Database (Its texts with “~” as spaces (they need to be stripped out before displaying. Then put the text into an existing variable so assign a string …example: rowLabel = (value from the Javascript or Web).
[I am using/updating the free script “GUITouchScroll.cs”.]

Your help would be Greatly appreciated!

The problem you cannot simply reference any variable from a script written in JS from a script in C# is because both languages are compiled at the same time. So when you ‘reference’ something in an other language the compiler doesn’t know about what you’re referencing yet and will throw an error. So the problem is compilation order.

If you’ve clicked that link you basically already know what to do. Put the JS script you want to reference in a folder called “Standard Assets” or “Plugins” in the root of your project. Then you can simply reference it from any script in any language, so for instance from C# it would be:

string messageToAccess = NameOfTheJSScript.nameOfTheStaticVariable;

This is awesome… Thanks for your help!!
I will try this and post any updates or issues.

DJKR,This is awesome… I will try it, and let you know…

Thank-You Soooooooo Much!!

You could use SendMessage in your Javascript File. Not sure how efficient this is, or if the code below works as it… (5am programming)


In your JS:

var livesCount : int = 3;

function Update ()
SendMessage("GetLivesCount", livesCount)

Now in your CS:

private int livesCount;
void GetLivesCount(int jsLivesCount)
   livesCount = jsLivesCount;

Been struggling with this, but still can’t get it.
Is there anyone who would accept pay to help resolve this?
I need help fast.
Please email me: ,Thanks, but still having problems (I’m a noob to c#)… I’ll pay someone to help me. Please email me

Found the Solution:

Thanks for your replies!.. I ended up creating a prefab in the Javascript - and converting it all over to use just Javascript… then I could drag and drop a prefab with the attached JavaScript into the (Required) Variable that had the Null.

Again, I appreciate your responses!