Page 1 of 1

Expressions, how they really work

Posted: Fri Feb 28, 2020 4:10 pm
by quazoosl
Hi,

I didn't find the help file very useful for experssions, I've rewritten it for how they really seem work in v6.20

Code: Select all

Definitions:
	true		not 0
	false		0

Functions
	PI 		3.1415926535897932385
	COS(x)		Cosine of x degrees	
	SIN(x)		Sine of x degrees
	TAN(x)		Tangent of x degrees
	ACOS(x)		Arc cosine of x degrees
	ASIN(x)		Arc sine of x degrees
	ATAN(x)		Arc tangent of x degrees
	ATAN2(x,y)	ATAN(x/y)
	EXP(x)		e^x
	LN(x)		log_e⁡x
	LOG(x)		log_10⁡x
	SQRT(x)		√x
	ABS(x)		|x|
	MAX(x,y)	Returns largest value of x and y
	MIN(x,y)	Returns smallest value of x and y
	CEIL(x)		Rounds x off to closest higher whole number
	CEIL2(x,y)	Rounds x off to closest higher number divisible by y
	ROUND(x)	Rounds x off to closest whole number
	ROUND2(x,y)	Rounds x off to closest number divisible by y
	FLOOR(x)	Rounds x off to closest lower whole number
	FLOOR2(x,y)	Rounds x off to closest lower number divisible by y
	
Logic	(Logical functions and comparisons return 1 when true, and 0 when false)
	Functions
		AND(x,y)	x and y are true
		OR(x,y)		x or y is true
		NOT(x)		x is not true
		WHEN(x,y,z)	Returns y if x is true, z if x is false
		
	Comparison 	
		x==y		x is equal to y
		x>=y		x is larger than or equal to y
		x>y		x is larger than y
		x<=y		x is smaller than or equal to y
		x<y		x is smaller than y
		x!=y		x is not equal to y
Note: the amount of arguments is exact, so this does not work:

Code: Select all

and(x,y,z)

but this does:

Code: Select all

and(x,(and(y,z)) 

Re: Expressions, how they really work

Posted: Fri Feb 28, 2020 10:27 pm
by RaudMees
Hello

expressions in TS a bit strange for beginners. It's a mixture of several programming languages. I was in deep sh*t in the beginning, but now my expressions working well. Usually they are up to 20 characters long, but in some cases they can be more than 400 characters :)
For better understanding it's good to start with simple things. Rounding, switching components on/off etc.

RM

Re: Expressions, how they really work

Posted: Mon Mar 02, 2020 8:35 am
by quazoosl
RaudMees wrote: Fri Feb 28, 2020 10:27 pm ... Usually they are up to 20 characters long, but in some cases they can be more than 400 characters :) ...
I would try to avoid that. Having to figure out how a 400 character expression works is quite hard, even if you're the one that has made it. Not to mention having to figure out why it breaks. Why not cut it up into smaller pieces and refer to those?

Re: Expressions, how they really work

Posted: Mon Mar 02, 2020 1:46 pm
by Derpomagix
Personally, I have found that breaking expressions down into chunks to do specific jobs, and then calling them into a single function, works best.

Breaks a lot less and is generally more reliable.

Re: Expressions, how they really work

Posted: Wed Mar 04, 2020 10:43 pm
by RaudMees
In some cases its easier to read and handle when expressions is in one long line.
2 examples here:

when(num_9==1,pos_9+s_f_m,when(num_8==1,pos_8+s_f_m,when(num_7==1,pos_7+s_f_m,when(num_6==1,pos_6+s_f_m,when(num_5==1,pos_5+s_f_m,when(num_4==1,pos_4+s_f_m,when(num_3==1,pos_3+s_f_m,when(num_2==1,pos_2+s_f_m,when(num_1==1,pos_1+s_f_m,-o_f_ö_1)))))))))

when(d<300,1,when(d<501,2,when(d<701,3,when(d<900,0,0))))

RM

Re: Expressions, how they really work

Posted: Thu Mar 05, 2020 8:47 am
by quazoosl
fair point, the expressions available are quite limited and sometimes you're going to have to make do.

If the num values are only ever 1 or 0 you could replace num_1==1 with just num_1 and keep the same functionality.

Personally I would probably split this up in two and something like this:

Code: Select all

chosen_pos 	when(num_9,pos_9,when(num_8,pos_8,when(num_7,pos_7,when(num_6,pos_6,when(num_5,pos_5,when(num_4,pos_4,when(num_3,pos_3,when(num_2,pos_2,when(num_1,pos_1,-o_f_ö_1)))))))))
pos_corrected	when(chosen_pos==-o_f_ö_1,chosen_pos,chosen_pos+s_f_m)
But to each his own of course :)