✅ Getting array values through Reflection
I'm making an "interpreter" using reflection but I don't know how to access the value of array elements. I've tried with IEnumerators this way:
But I get this error:
On the line I retrieve the value.
(also any other way of making an interpreter in unity that you can think of, please tell)
23 Replies
what language are you interpreting?
My own, i guess
a custom scripting language? fair enough, why are you using reflection in that case?
Because I'm kind of a beginner xD
no real need to, you just need to "translate" your scripting language into managed C#
And didn't know where to start on creating an interpreter
Have you checked out $craftinginterpreters?
if you're new that's going to be a lot
proper interpreters are a significant amount of work
Bear in mind that I'm on Unity
you can make simple DSL/scripting languages fairly easily by just reading the script and "converting" it to C#
It's just a tcg game, and I want to be able to code the execution of cards through a text file
You could use C# scripting for that if you wanted
actually compiling code in Unity is a bit of a headache no?
though really if you're trying to make your game moddable, there are better ways
if you're just writing this purely for yourself, there's no reason not to just write the code in C# to begin with
Nah, i did it that way before, now I want something of a challenge xD
For instance?
loading compiled binaries at runtime is a better choice than actually compiling the code
you can just frankly use BepinEx or something to save yourself some work, that'll largely handle everything for you
it depends on what your overall goal is, if you just want to make a simple DSL for the fun of it then go for it
I don't like having to work with pluggins, even less if they are so specific as to only work with unity, like to make the tools myself
custom scripting lang...
in C#
something like this would work for a very simple DSL
if you want a genuine true interpreter, then yeah you'd better read $craftinginterpreters and settle down for a few months of hard work
Right, emm, the objective of the code above is actually to access an array on the GameManager
Not to store information
not 100% what you're actually trying to achieve, but getting array values is easy enough
It works! thanks!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.