Page 1 of 1

Ending If Statements

PostPosted: Mon Jan 20, 2014 11:00 pm
by JustynR
Is there a way I can have multiple If else statements in one Action Script or button?

I have 24 buttons I would like to turn green when it is pushed - and have any other one that is green turn back to grey.

I would like to make this happen without putting:

WDCustomScript,1,0,255,0

WDCustomScript,2,128,128,128
WDCustomScript,3,128,128,128
WDCustomScript,4,128,128,128
...

What I'd like is to use a variable:

if ButtonClicked = 1
{
WDCustomScriptTint,1,0,255,0
}
else
{
WDCustomScriptTint,1,128,128,128
}

and button click 2 and so on...
The first one in the script works, but as soon as I add the second or third one, it executes each if argument - it turns all of the buttons green...

Do I need to add:

esle
fi

at the end of each argument? Would that work with WD? (I don't have it open right now)...

I hope I can get a quick answer on this! This show is tomorrow - it is all working... just trying to make the GUI more user friendly without going crazy with scripting....

OR is there another way I'm not thinking of to do this?

Cheers,

Re: Ending If Statements

PostPosted: Tue Jan 21, 2014 3:09 am
by malkuth23
Coming soon...

Re: Ending If Statements

PostPosted: Tue Jan 21, 2014 3:40 am
by JustynR
Soon as in - feature to come?

or

You've got a solution?

Re: Ending If Statements

PostPosted: Tue Jan 21, 2014 11:53 am
by Dennis Kuypers
Hi Justyn,

I would solve this with a macro/action that resets all buttons to grey (1 and 10 to be replaced with the customscript ID range):
Code: Select all
For 1 to 10
WDCustomScriptTint,for.index,128,128,128
Next

An in each CS:
Code: Select all
WDMacro,ResetColors
WDCustomScriptTint,MyId,0,255,0


Note: The "MyID" works on WD rev. 516+ as a workaround you can introduce a "currentButton" INT variable and set it in the button prior to calling the macro. In the macro you also do "WDCustomScriptTint,currentButton,0,255,0"

Best regards
Dennis

Re: Ending If Statements

PostPosted: Thu Jan 23, 2014 3:47 pm
by JustynR
Love it!

Thank you!

I will do this next time...!

Re: Ending If Statements

PostPosted: Wed Feb 03, 2016 3:56 pm
by chrisr
Gents,
Thanks for posting this, I have tried the solution here but am struggling with it.

This is what I've done.

Macro -(ResetColors)

For 1 to 256
WDCustomScriptTint,for.index,128,128,128
Next

And as you said put this in the Click Script of the CS button:

WDMacro,ResetColors
WDCustomScriptTint,MyId,0,255,0

Does there need to be an "if" statement in the CS button? As I move through and click each button, they turn green and do not return to the reset color state. I know you both have discussed this, so I apologize that I'm re-asking about this. Also, I did see the if then statements Justyn was speaking of. I have a button array of 256 buttons in a grid. so my goal is to turn each button green (if clicked) and if any other buttons are green they will reset back to gray. There was a note about a workaround you can introduce a "currentButton" INT variable and set it in the button. I wasn't quite following this.

Have a great day! Thanks!

Changing a Button Colour and Return the other buttons to def

PostPosted: Wed Feb 03, 2016 10:04 pm
by chrisr
JustynR wrote:I have 24 buttons I would like to turn green when it is pushed - and have any other one that is green turn back to grey.


This is how I Did this, again thanks to Justyn for some help on another project to tie this together. Not sure if this is the slickest way to do this, but here it is.

This Project is Ten buttons to keep it small for testing purposes. If you want the button you click to turn a colour and return the other buttons in the array back to their default state:

Macro: Named "Bank1" for this test

For 1 to 10
WDCustomScriptTint, for.index,0,100,200
Next
WDCustomScriptTint,CurrentButton,0,255,0

CustomScript Button Click Script Box:

WDMacro,Bank1

CustomScriptButton Mouse over Script Box:

CurrentButton = MyId

Variable written was CurrentButton / String / Value was the mouse over which populated MyId

Re: Ending If Statements

PostPosted: Thu Feb 04, 2016 10:19 am
by AViefhues
Hi together,

I normaly use functions for this, it is more generally:

Function_Name: BTNColorchange{StartID,EndID,ActiveID}

For StartID to EndID
WDCustomScriptTint,for.index,128,128,128
Next
WDCustomScriptTint,ActiveID,0,255,0

In your case you would call the function in every Button:

BTNColorchange{1,256,MyID}


you just have to take care about the Button IDs, this could sometimes be hard if you add buttons later to your project.
For this case it would be grate to have an easy way to change or shift ControlIDs.


regards
Alex

Re: Ending If Statements

PostPosted: Thu Feb 04, 2016 6:48 pm
by chrisr
Alex,
Thanks for this. I will play with this. I have redone the button array so it is very organized. The array starts at 601 and Ends at 856. A 256 Button Array. The buttons, I want in groups of 16. I accomplished this with the For 601 to 616 Macro1 then a new macro for each button group. Thanks for your method. I will test this out.

Regards,

Re: Ending If Statements

PostPosted: Fri Feb 05, 2016 11:30 am
by Dennis Kuypers
I'll just leave that here...


Code: Select all
' Create a new project, add 400 CustomScript Buttons and then run this script

' cleanup
VDeleteAll

' Settings
vint,totalcols,20
vint,totalrows,20
vint,controlsize,50

' Prepare vars...

' current column and row
Vint,col,0
Vint,row,0

' current offset for the button
Vint,offsetx,0
Vint,offsety,0

' "realid" is a misnomer. To get the row and column we divide
' the control ID by the column count and row count. Because of
' rounding we would end up with buttons half a column offset.
' So what we do is take the current id and offset it so that
' we get a proper row. This is done in the loop
' subtract
vdouble,realid,0

' name of the control (needed to position and resize)
vstring,controlname,

' color to set to
vint,red,0
vint,green,0
vint,blue,0

' calculated total number of controls
vint,totalcontrols,0
vmultiply,totalcontrols,totalcols,totalrows

' To distribute the 8-bit of the colors throughout
' the columns and rows we need a factor to multiply with
vdouble,colorfactorx,0
vdouble,colorfactory,0
vdivide,colorfactorx,255,totalrows
vdivide,colorfactory,255,totalcols

' The first loop hides and resizes all buttons
For 1 To totalcontrols

' concatenate the name of the control
' "CustomScript" & ID
VValue,controlname,CustomScript
VAdd,controlname,controlname,for.index

' Hide & Resize
WDControlHide,controlname
WDControlSetSize,controlname,controlsize,controlsize

Next


' Black background for contrast
WDPageBackgroundColor,Default,0,0,0

' position and colorize buttons
For 1 to totalcontrols

' "realid" calculation, see remarks at top of code
VDivide,realid,totalcols,2
VSubtract,realid,for.index,realid
VSubtract,realid,realid,0.5

' Get the row and the red value for control
VDivide,row,realid,totalcols
VMultiply,offsety,row,controlsize
VMultiply,red,row,colorfactorx

' because we have stored the "offsety" we can modify the row with no harm
' calculate column
VMultiply,row,row,totalcols
VAdd,row,row,1
VSubtract,col,for.index,row
VMultiply,offsetx,col,controlsize
VMultiply,green,col,colorfactory

' control name...
VValue,controlname,CustomScript
VAdd,controlname,controlname,for.index


' red and green are controlled by the x and y
' position of the button. In the top left corner
' there is black. To avoid that let's put in some
' blue where no other color is present
VSubtract,blue,255,green
VSubtract,blue,blue,red
If blue < 0
{
blue=0
}

' position, colorize and show
WDControlSetPosition,controlname,offsetx,offsety
WDCustomScriptTint,for.index,green,blue,red
WDControlShow,controlname

Next

Re: Ending If Statements

PostPosted: Fri Feb 05, 2016 4:04 pm
by chrisr
DENNIS! Awesome, Colorful. Thanks for this bit. Now I can see how you can quickly manage a lot of CS buttons. and Colorize them. I appreciate the help.



Cheers

Chris