cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
Developer forum

Swap A and B parameters

A_ Smith
Advocate

Tbh I feel silly to ask such basic question, but I can't figure out how to swap values for A, B.

If additional parametes are created it's easy to change their values based on constant A, B. Though how to do it when with help of 2 parameters only? preferably main A, B.

 

https://drive.google.com/file/d/1TuKbeIqsUdWjve0QYYlYH62h2HNA5-T7/view?usp=drivesdk

AC 22, 24 | Win 10
1 ACCEPTED SOLUTION

Solution

If I change the script to following it works for me:

temp_A = A
temp_B = B

IF GLOB_MODPAR_NAME = "bSwap" then
	IF bswap = 1 THEN
		A = temp_B
		B = temp_A
		PARAMETERS A = A
		PARAMETERS B = B
		PARAMETERS bSwap = 0
	ENDIF
endIF
Joachim Suehlo . AC12-26 . MAC OSX 10.15 . WIN10

View solution in original post

13 REPLIES 13

DGSketcher
Champion

@A_ Smith You need to clarify a bit more about where you are changing the values e.g. param-o or in a GDL script? In gdl you will need to create swap values e.g. a1 & b1 if you don’t want to loose the originals. You could also do a similar thing with Find & Replace.

Apple iMac macOS Monterey / AC26UKI (most recent builds)

GDL.

In parameter script I planned to swap A, B - at least for now (when "bSwap" is true), without saving original values. Kinda temp=A, A=B, B=temp

 

Originally I wanted to swap values each! time "bSwap" is changed... Just in order to find out why that doesn't work, decided to make it simpler.

AC 22, 24 | Win 10

Lingwisyer
Legend

I would:

 

IF GLOB_MODPAR_NAME = bSwap then
temp = A
A = B
B = temp
PARAMETERS A = A
PARAMETERS B = B
PARAMETERS bSwap = 0
endIF

 

 

Ling.

AC22-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | R5 2600 | 16GB | GTX1660

Creating a Thread
Help Those Help You - Add a Signature

Right, but that doesn't work...

AC 22, 24 | Win 10

Try Ling's Parameter Script extract without the 'Parameters bSwap = 0' you will then know if the values are swapped.

Apple iMac macOS Monterey / AC26UKI (most recent builds)

Well, I know it without deleting that row - it doesn't work as expected. I see that values don't change. Just to be sure, I removed it - all remais the same.

 

Unfortunatelly trying to help without actually checking it, doesn't do the job. Because, it's so simle lines of code (strange to say it though) that can't be wrong. Nevertheless they do not obey.

AC 22, 24 | Win 10

Solution

If I change the script to following it works for me:

temp_A = A
temp_B = B

IF GLOB_MODPAR_NAME = "bSwap" then
	IF bswap = 1 THEN
		A = temp_B
		B = temp_A
		PARAMETERS A = A
		PARAMETERS B = B
		PARAMETERS bSwap = 0
	ENDIF
endIF
Joachim Suehlo . AC12-26 . MAC OSX 10.15 . WIN10

Indeed. Thanks.

 

Though, my brain still can't except that this works only due to overriding bSwap - "parameters bSwap=0". Without it should work too, right? just instead I would have to 'unckeck' bSwap and then make it true again (but that doesn't work).

 

AC 22, 24 | Win 10

If you wanted to, you could double the script within the ModPar with IF bSwap = 1 then Else endIF. By doing this it should just keep swapping each time you check it.

AC22-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | R5 2600 | 16GB | GTX1660

Creating a Thread
Help Those Help You - Add a Signature

DGSketcher
Champion
One for Grand Master @Peter Baksa I think. There appears to be some value protections in place for A, B & ZZYZX which don't apply to other parameters. 
 
In the following, the values of A1 & B1 swap but the values of A, B & ZZYZX remain static...

 

!PARAMETER SCRIPT
!Create values for bSwap (boolean) and A1 & B1 (real) in the parameters 

	A1 = A
	B1 = B

	PARAMETERS A1 = A1, B1 = B1

	IF GLOB_MODPAR_NAME = "bSwap" THEN 
	
		IF bSwap = 1 THEN
			A = B1
			B = A1
			ZZYZX = A1
		ELSE
			A = A1
			B = B1
			ZZYZX = B1
		ENDIF
		
		PARAMETERS A = A, B = B, ZZYZX = ZZYZX
	
	ENDIF

 

Apple iMac macOS Monterey / AC26UKI (most recent builds)

If I change the script to the following, it works for me (AC 22 and 26 on macOS)

!PARAMETER SCRIPT
!Create values for bSwap (boolean) and A1 & B1 (real) in the parameters 

	A1 = A
	B1 = B

	PARAMETERS A1 = A1, B1 = B1

	IF GLOB_MODPAR_NAME = "bSwap" THEN 
	
		IF bSwap = 1 THEN
			A = B1
			B = A1
			ZZYZX = A1
		ELSE
			A = A1
			B = B1
			ZZYZX = B1
		ENDIF
		
		PARAMETERS A = A, B = B, ZZYZX = ZZYZX, bSwap = 0
	
	ENDIF
Joachim Suehlo . AC12-26 . MAC OSX 10.15 . WIN10

Logic failure on my part. 🙄 Without setting bSwap back to Zero the swap would be constantly valid and would try to change A & B every time the Parameter script was run.

 

So @A_ Smith a working solution...

 

 

!PARAMETER SCRIPT
!Create values for bSwap (boolean) and A1 & B1 (real) in the parameters 


	IF GLOB_MODPAR_NAME = "bSwap" THEN 
	
		A1 = A
		B1 = B
		PARAMETERS A1 = A1, B1 = B1

		IF bSwap = 1 THEN
			A = B1
			B = A1
		ENDIF
		
		bSwap = 0

		PARAMETERS A = A, B = B, bSwap = bSwap
	
	ENDIF

 

 

OR use @Joachim Suehlo earlier solution which I missed due to this stupid forum formatting.

Apple iMac macOS Monterey / AC26UKI (most recent builds)

Lingwisyer
Legend

Odd... since I have replaced the A, B and ZZYZX values in objects before...

AC22-23 AUS 7000
Self-taught, bend it till it breaks.
Win10 | R5 2600 | 16GB | GTX1660

Creating a Thread
Help Those Help You - Add a Signature

Still looking?

Browse more topics

Back to forum

See latest solutions

Accepted solutions

Start a new discussion!