Storing a conditional expression as a structure field

Just starting out? Need help? Post your questions and find answers here.
Quin
Posts: 118
Joined: Wed Nov 08, 2023 4:38 pm

Storing a conditional expression as a structure field

Post 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!
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Storing a conditional expression as a structure field

Post 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
Quin
Posts: 118
Joined: Wed Nov 08, 2023 4:38 pm

Re: Storing a conditional expression as a structure field

Post 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.
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Storing a conditional expression as a structure field

Post 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?
Quin
Posts: 118
Joined: Wed Nov 08, 2023 4:38 pm

Re: Storing a conditional expression as a structure field

Post 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.
User avatar
Caronte3D
Posts: 189
Joined: Sat Nov 23, 2019 5:21 pm
Location: Some Universe

Re: Storing a conditional expression as a structure field

Post 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.
Post Reply