Newbie Question Help with Simple Logic Script… if / else

Discuss and share scripts and script files...
Post Reply
Lusayalumino
Posts: 90
Joined: 13 Aug 2018 07:16
Location: USA

Newbie Question Help with Simple Logic Script… if / else

Post by Lusayalumino »

I’m trying to build a simple logic script, attached to a keyboard shortcut, that Toggles between two layouts.

I don’t have any coding background, but I’m familiar with the way excel does a logic statement: =if(logical text, value if true, value if false)

ALWAYS RETURNS 2 PANES NORMAL:
I think the problem I’m having, is that the script doesn’t stop after the first argument is checked, even if it is true:
if (layout ! 2 Panes Minimal) {loadlayout(2 Panes Minimal);} loadlayout(2 Panes Normal);}

ALWAYS ALWAYS RETURNS 2 PANES MINIMAL:
I think the problem I’m having here, is the exact opposite, always stops after the first argument is checked:
if (layout ! 2 Panes Minimal) {loadlayout(2 Panes Minimal);} else {loadlayout(2 Panes Normal);}

Any help would be greatly appreciated!
XYPlorer, Great Form -- Awesome Function

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Newbie Question Help with Simple Logic Script… if / else

Post by highend »

! is a logical NOT
! is not a valid comparison operator (only as a !=)

Regarding your first example: There is no else?

Should these lines really be scripts or just an example of your (not posted) real scripts?
One of my scripts helped you out? Please donate via Paypal

Lusayalumino
Posts: 90
Joined: 13 Aug 2018 07:16
Location: USA

Re: Newbie Question Help with Simple Logic Script… if / else

Post by Lusayalumino »

highend wrote: 04 Oct 2019 22:19 ! is a logical NOT
! is not a valid comparison operator (only as a !=)
Gotcya; thanks!
highend wrote: 04 Oct 2019 22:19 Regarding your first example: There is no else? Should these lines really be scripts or just an example of your (not posted) real scripts?
Those were my actual scripts (written on one line); when I write them as follows, a popup opens with two scripts that I have to choose from:

if (layout != 2 Panes Minimal) {
loadlayout(2 Panes Minimal);
}
else {
loadlayout(2 Panes Normal);
}
XYPlorer, Great Form -- Awesome Function

highend
Posts: 13309
Joined: 06 Feb 2011 00:33

Re: Newbie Question Help with Simple Logic Script… if / else

Post by highend »

You are comparing strings. Single / double quote them!
a popup opens with two scripts that I have to choose from
Your script isn't properly indented
One of my scripts helped you out? Please donate via Paypal

jupe
Posts: 2788
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Newbie Question Help with Simple Logic Script… if / else

Post by jupe »

Also besides the already mentioned issues, this will never work:

if (layout != 2 Panes Minimal) {

assuming that is meant to be a variable it would need to have a $ prefix, and also assuming what you have shown is your entire script, it would need to have a value assigned to it, which you haven't done.

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Newbie Question Help with Simple Logic Script… if / else

Post by klownboy »

A little more assistance... I think your best bet is to determine what layout feature or possibly a view setting is unique to one of your saved layouts (i.e., a feature that you have in one layout but not the other). SC loadlayout does not provide a return (i.e., text loadlayout () is not going to tell you a layout name that is currently loaded or in use). SC setlayout () will give you the details of the current layout. So for example: one of your saved layouts has a dual pane, the other does not. Then you could test to see if you are currently in a Dual pane. If not, go to layout called "Dual Pane". If you are in a dual pane mode than loadlayout ("Single Pane"). So in this example:

Code: Select all

  if(get "#800") {loadlayout ("Single Pane");}
  else {loadlayout ("Dual Pane");}
Another check might be for a particular view in one layout that's not in the other. (e.g., thumbnail #3 in one layout and the other layout is detail view).

Code: Select all

  if(get("View") == '6') {loadlayout ("whatever");}
  else {loadlayout ("different whatever");}
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Lusayalumino
Posts: 90
Joined: 13 Aug 2018 07:16
Location: USA

Re: Newbie Question Help with Simple Logic Script… if / else

Post by Lusayalumino »

Cool... thanks; I had basically given up.

Here are teh differences between the layouts:
#663 Show Nav Panels
#671 Breadcrumbs Bar
#670 Status Bar
#681 Address Bar / Toolbar Stacked

I tried this will all four:
if(get "#CMD") {loadlayout ("2 Panes Normal");}
else {loadlayout ("2 Panes Minimal");}

On all 4, they worked on first run; then stopped working.

Regarding Get View... there are no differences in the views; only in the window menu options.
XYPlorer, Great Form -- Awesome Function

jupe
Posts: 2788
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Newbie Question Help with Simple Logic Script… if / else

Post by jupe »

Something like this should work:

Code: Select all

	if (setlayout( , <crlf>) == gettoken(readfile("<xydata>\Layouts\2 Panes Normal.txt"), 2, <crlf>, , 2)) {
		loadlayout("2 Panes Minimal"); }
	else {  loadlayout("2 Panes Normal");  }

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Newbie Question Help with Simple Logic Script… if / else

Post by klownboy »

Sorry Lusayalumino I messed up the syntax. It should have been

Code: Select all

   if(get("#663")) {loadlayout("2 Panes Minimal");}
   else {loadlayout("2 Panes Normal");}
I forgot a second set of parenthesis around the #CID. Jupe has a very nice solution though. I'd use that. :)
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Lusayalumino
Posts: 90
Joined: 13 Aug 2018 07:16
Location: USA

Re: Newbie Question Help with Simple Logic Script… if / else

Post by Lusayalumino »

klownboy wrote: 06 Oct 2019 13:09 Sorry Lusayalumino I messed up the syntax. It should have been

Code: Select all

   if(get("#663")) {loadlayout("2 Panes Minimal");}
   else {loadlayout("2 Panes Normal");}
I forgot a second set of parenthesis around the #CID. Jupe has a very nice solution though. I'd use that. :)
That works... THANK YOU KlownBoy!
XYPlorer, Great Form -- Awesome Function

Lusayalumino
Posts: 90
Joined: 13 Aug 2018 07:16
Location: USA

Re: Newbie Question Help with Simple Logic Script… if / else

Post by Lusayalumino »

jupe wrote: 06 Oct 2019 07:51 Something like this should work:

Code: Select all

	if (setlayout( , <crlf>) == gettoken(readfile("<xydata>\Layouts\2 Panes Normal.txt"), 2, <crlf>, , 2)) {
		loadlayout("2 Panes Minimal"); }
	else {  loadlayout("2 Panes Normal");  }
This also works perfectly... thanks Jupe!
XYPlorer, Great Form -- Awesome Function

klownboy
Posts: 4139
Joined: 28 Feb 2012 19:27

Re: Newbie Question Help with Simple Logic Script… if / else

Post by klownboy »

I mentioned using jupe's version earlier. The reason for that is when you are basing the if/else condition on one attribute, like CID#663, though it's very quick, if you were to use some additional layouts or configurations other than the 2 layouts being cycled, it's possible the layout change could possibly run afoul (though maybe not). Whereas jupe's is essentially checking every attribute of the existing layout, but the disadvantage of that is the reading of the layout file then checking it against all the attributes of the existing layout which equates to some extra milliseconds that you probably wouldn't even notice anyway. :)
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Lusayalumino
Posts: 90
Joined: 13 Aug 2018 07:16
Location: USA

Re: Newbie Question Help with Simple Logic Script… if / else

Post by Lusayalumino »

Very helpful, thorough, and precise. Almost as though I was being helped by a nuclear engineer :ugeek: :tup:
XYPlorer, Great Form -- Awesome Function

Post Reply