Skip to content

Passing C# field through javascript and back into C# results in null #87

Open

Description

Here is my setup:

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?

Activity

  1. oliverbock commented on Apr 27, 2020

    @oliverbock
    Contributor

    I think only public properties will go through to JavaScript. Obviously if your displayr_name is null then that is your problem.

  2. oliverbock commented on Apr 28, 2020

    @oliverbock
    Contributor

    Try to reduce this to a simple example that you can post here.

  3. oliverbock commented on Apr 29, 2020

    @oliverbock
    Contributor

    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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions