- Home /
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#?
ORIGINALLY I WAS TRYING TO DO THIS:
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! Thanks! DJKR
Answer by Joshua · Aug 24, 2011 at 05:16 AM
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;
Answer by djkr · Aug 24, 2011 at 06:14 AM
This is awesome... Thanks for your help!! I will try this and post any updates or issues.
Cheers! :) DJKR,This is awesome... I will try it, and let you know...
Thank-You Soooooooo Much!! :) DJKR
Answer by SrBilyon · Aug 24, 2011 at 09:00 AM
You could use SendMessage in your Javascript File. Not sure how efficient this is, or if the code below works as it... (5am programming)
Example:
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;
}
Answer by djkr · Aug 25, 2011 at 11:21 PM
Thanks, 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: djkr@djkr.fm ,Thanks, but still having problems (I'm a noob to c#)... I'll pay someone to help me. Please email me Djkr@Djkr.fm Cheers K
Answer by djkr · Sep 13, 2011 at 07:35 PM
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!
Cheers, Kris
Your answer
![](https://koobas.hobune.stream/wayback/20220612191002im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Problem Javascript to C# 3 Answers
dealing with gameObject formations 1 Answer
Javascript equivalent of an inspector C# public List? 1 Answer