Is there any way to represent a variable used for a final product? I am trying to print an answer to a math algorithm I am trying to make but I do not know how to use variables in final answers (the letter shown in red in the badly drawn picture)
This is quite confusing, are you able to explain in further detail?
I was confused on how to write this
So in algebraic expressions, some outcomes will have an answer that looks like this:
And I was wondering if it was possible to have some sort of variable (like x in the example) that would equal a numerical answer. This is difficult for me to explain but I hope this clarified it a little.
I’m not sure if you can exactly do this, but maybe with
string.split and some table magic, you could make something close to it.
I made a (sort-of) example that basically re-writes math expressions, and if the variables are defined in a table, it will be replaced with its value.
local function Solve(Math, Variables)
for Variable, Value in pairs(Variables) do
Math = string.gsub(Math, Variable, Value)
You can definitely expand upon this to make it be able to add, subtract, multiply, other stuff. This is only an example, but you can add some functionality to it so it can solve these problems.