You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Passing C# field through javascript and back into C# results in null #87
I plan to use JavaScript as the language for modding my game, I currently have it setup to create a javascript context with 3 variables: log, mod and require, require isn't being used yet...
mod is a C# object with the field I am trying to use. log is also a C# object with functions that redirect to log4net, (mainly info(string format, object[] objs))
Here is the issue, in my javascript file I have:
log.info("Hello from {0}!", [mod.display_name]);
Which results in:
Hello from !
Even though mod's C# object has the field display_name set to "sandbox"
I even checked with the debugger, the C# instance of mod is correct, I debugged the C# function for log.info and noticed that mod.display_name was evaluating to null before being passed through the function. Why is this happening? And how can I fix it?
Yes, I don't think fields are supported. You get null rather than an error when a property does not exist. (This is convenient sometimes, and not other times. Your object can also store arbitrary new properties, if I remember correctly.)
Activity
oliverbock commentedon Apr 27, 2020
I think only
publicproperties will go through to JavaScript. Obviously if yourdisplayr_nameis null then that is your problem.oliverbock commentedon Apr 28, 2020
Try to reduce this to a simple example that you can post here.
oliverbock commentedon Apr 29, 2020
Yes, I don't think fields are supported. You get null rather than an error when a property does not exist. (This is convenient sometimes, and not other times. Your object can also store arbitrary new properties, if I remember correctly.)