Squiffy OR

I've got a game where I need a squiffy logical OR (I could do it easy in JS but this is deep in squiffy territory). A logical AND would look like this...

{@a}
{@b}

{if a:{if b: AND}}

Any ideas?


Hello, Bluevoss!

This works in the ScratchPad thing in the Squiffy documentation, but that doesn't always mean it works in the latest version of Squiffy.

{@a}
{@b}

{if a:{if b: AND}}

{if c:AND}{else:BUT}

I found the else code here:

https://github.com/textadventures/squiffy/blob/1ea68ad48a51980cc22ab4b5a6758ced700eaff1/examples/sectiontrack/sectiontrack.squiffy#L14


For a logical or, I think you need a temporary value

{@not temporary_value}
{if a:{@temporary_value}}
{if b:{@temporary_value}}
{if temporary_value:Woo! A or B is true!}

Or, harder to read but more efficient:

{if a:{@temp}}{else:{if b:{@temp}}{else:{@not temp}}}
{if temp:This is the result of your logical or}

MR, I liked your solution but I've got a string of these to do and I don't think temp is resetting. For this, I might try something like this...

{@a}
{@b}

{@not temp}{if a:{@temp}}{if b:{@temp}}
{if temp: Local OR true}

Oh . . .

I misunderstood the question. (I should have known Bluevoss already knows how to work else in Squiffy.)


And my second one had a silly typo.

I think what you have there is the same as my first one with the line breaks removed; unless I made another mistake.


Richard - you'd think I knew, but you can't imagine the number of times I've still goofed up simple commands. My favorite is the five hours I recently spend fussing with squiffy code because there was a space in a command. I looked straight at it for hours.

Mrangel - As mentioned above, yeah, we all make them. And it was only now that I realize what "{if b:{@temp}}" was doing. And now (today) I see it - you were setting temp in case it wasn't set (which I moved to the front of the operation, same difference).

But thanks all you guys for your responses. You both put me on the right track.

(And it's remarkable that a logical OR was far more difficult then a natural logical AND. And that I've never had need for it until now)


Well, if you see a new programmer who doesn't know about logical operations, they often end up with stuff like:

if (a) {
  if (b) {
    Wow! a AND b!
  }
}

if (a) {
  Wow! a OR b
}
elseif (b) {
  Wow! a OR b
}

Which is technically faster; but involves typing out your code twice.


There should be an easier way - I could do it in JS very easy but I wanted to keep it all in one code base. But since I had something like twenty lines of OR checks, the two line option we co-developed was much better.

Of course, while I say this is critical, I'm mindful that it's never come up (across something like a half-dozen written games) until now.


To be honest, I'm surprised that simple logic isn't supported by default. It would be like a half dozen lines to implement; a dozen if you want a simple push-down lexer so you can do grouping like (a and b) or (c and d)


Damn, I woke up today and there was the answer, clear as day!

{@a}
{@b}

{if a:{if b: AND}}

{if not a:{if not b:}}
{else: OR}

Simple!


Of course, should bave remembered de Morgan's laws.

Good solution :)


This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums