Quantcast
Channel: Questions in topic: "parser"
Viewing all articles
Browse latest Browse all 108

Conditional expressions parser? How to manage conditions out of a C# script?

$
0
0
This will be more a question about programming in general, than about Unity. But! I would really be very pleased if someone shows me a way how to manage the issue.
Assuming we have a LightBulb class. It can be turned on and off. Simple. We also have a global variables database, say, Dictionary (string, int) or something else. So we can have, i.e. 3 wood, 19 stone, killedTheOldLady = 1 (not "true", just to simplify), and so on.
Now we want the LightBulb class to have another field. "string condition". We can put here some expression like, hypothetically, "wood == 5 && stone == 5". Now when we create our database we can put there any variable we make up and the corresponding value, and we want each instance of LightBulb we created turn on if its condition was met.
For example, in the console, we could log the state of each bulb we have instantiated, or simply put some circles into the scene, that can change color depending if it's on or off
My question is: what is the simplest way to do it?
1. Writing my own parser/compiler of my own language is, as you can understand, very funny. I'm just a beginner. But I know I should code how the string should be interpreted 2. Embed Lua, Python, I don't know, JS! They all already have their own logic and I could somehow figure out how to translate from C# to a scripting language and back. This seems more simple. 3. Parse conditions from XML, where conditions are arguments? I've heard about it, but is this the easiest way to do it?
Please tell me, what should I do for my stupid branching text adventure =)

Viewing all articles
Browse latest Browse all 108

Trending Articles