Page 1 of 1

Storing a conditional expression as a structure field

Posted: Thu Sep 26, 2024 8:43 am
by Quin
I have a structure like so:

Code: Select all

Structure Quest
  Name.s
  Unlocked.b
  Requirements.?
EndStructure
I'm trying to figure out what the type of the requirements field should be. My thought is to make it a conditional expression that can be passed to Bool() and evaluated at runtime, but I'm unsure how to store that in a structure. Is this possible?
Thanks!

Re: Storing a conditional expression as a structure field

Posted: Thu Sep 26, 2024 10:37 am
by Caronte3D
I think your must separate the expression in variables and make an structure for each expression then you can make structure that contain other structures (expressions).
Or... you can save the expressions as strings and make a parser to evaluate it

Re: Storing a conditional expression as a structure field

Posted: Thu Sep 26, 2024 2:11 pm
by Quin
Thanks for your reply!
Option 2 is exactly what I wanted to avoid, the Bool() function does all this parsing for me and is probably more bulletproof than anything I could ever come up with.
Mind expanding on what you mean by your first suggestion? I don't quite get it.

Re: Storing a conditional expression as a structure field

Posted: Thu Sep 26, 2024 4:48 pm
by Caronte3D
Quin wrote: Thu Sep 26, 2024 2:11 pm Mind expanding on what you mean by your first suggestion? I don't quite get it.
Forget it, at a closer look seems not be a solution at all.

I don't know your case, but... Maybe you can use Regular Expressions in some way?

Re: Storing a conditional expression as a structure field

Posted: Thu Sep 26, 2024 5:40 pm
by Quin
My use case is honestly pretty simple, these structs represent quests in a game. I figured the easiest way to know what needs to be done to complete the quest would be to simply store it, for example, logsSold >= 100. All I need to be able to do is store something like this in my structures, and then pass it to Bool() at runtime to determine if the user completed the quest or not.

Re: Storing a conditional expression as a structure field

Posted: Thu Sep 26, 2024 7:58 pm
by Caronte3D
I think the best way is to do a procedure to parse the expresión, this way, you can store the expresión in plain text.