It's not perfectly clear what's your problem, so let's solve it from the end - which is your answer to your own problem - your function:
def InfluenceControl(infbase,distance,expo,distanceMax):
if distance < distanceMax:
return infbase - distance**expo
else:
return infbase - distanceMax**expo
Can be rephrased as a single line with the condition moved to a conditional operator controlling only the usage of distance vs distanceMax rather than alternating between whole formulas:
def InfluenceControl(infbase,distance,expo,distanceMax):
return infbase - (distance if distance < distanceMax else distanceMax)**expo
You use your "driver function" this way: InfluenceControl(1,var,-1,50) - the way you describe, the arguments never change (except the value under the name var changes). If that's the case, you can put those values inside the function:
def InfluenceControl(distance):
return 1 - (distance if distance < 50 else 50)**-1
What does distance if distance < 50 else 50 mean? It means: use distance, but make it no more than 50. So it can be replaced with clamping done by min function:
def InfluenceControl(distance):
return 1 - min(distance, 50)**-1
As you can see, not only it has become a one-liner, which you can use directly as a driver (and so you don't need to run a script that adds a function to the driver namespace, which makes the project easier to maintain), but is also more readable. Though an argument could be made, that using your original function is more readable if you used it with keyword arguments: InfluenceControl(infbase=1, distance=var, expo=-1, distanceMax=50).
Moreover, your original function allows to use it in various places, with various exponents and so on. You also reply to my remark in comments (var**-1 can be written as 1/var) with "it only works if exponentiation number is 1", which suggests you want to easily change it. If so, you should put it in your question!, and describe why, to avoid an XY Problem.
Arguably, a formula 1 - min(distance, 50)**-1 (if used in a driver, remember to rename var to distance!) is no less, and in fact much more readable than InfluenceControl(1, distance, -1, 50). Also I don't think a simple formula like that justifies a function that would guard consistency between different places where it's used, because IMHO the consistency is guaranteed by the logic of the formula. So just change an exponent, or max distance (I don't imagine you may want to change the 1 number) wherever you copy-paste the driver...
Finally, using either an external function InfluenceControl or the ** operator makes the driver a slow expression. Instead, use the function pow, so the driver becomes:
1 - pow(min(distance, 50), -1)
influence value is 0.95 when distance value is 17 influence value is 0.75 when distance value is 4.2 influence value is 0.1 when distance value is 1.
it needs to be like
influence value is 0.95 when distance value is 40 influence value is 0.5 when distance value is 30 influence value is 0.1 when distance value is 20
– Yokomizo Dec 11 '21 at 16:08var**-1can be written as1/var. 1/1.116 = 0.8960573476702508 ; 1 - 0.8960573476702508 = 0.1039426523297492 which rounds to 0.104, the result you get. – Markus von Broady Dec 11 '21 at 23:30