You generally can't change expressions in a script dynamically. There have been some "evaluate" functions posted on the forum that will allow a string to be evaluated as if it were an AHK expression, so you could look into those. Or you could have a number of different expressions available to be executed conditionally based on the user's input or something, but generally you cannot just define an expression dynamically and have AHK evaluate it.
By the way, my example of using functions that base their calculations on global variables was just to make it look more similar to your original script. It's best to write functions where you pass values to them as parameters, and their local variables are used inside the function:
Code: Select all
#Requires AutoHotkey v2.0
x := 0
y := 0
result1 := 2
result2 := 2.5
equations1(a, b) {
return a + b
}
equations2(a, b) {
return 0.5*a+2*b
}
loop{
if (equations1(x, y) = result1)
MsgBox("Yes")
else
MsgBox("No")
if (equations2(x, y) = result2)
MsgBox("Yes")
else
MsgBox("No")
x++
y++
}