You can pronounce the colon “otherwise” to make it easier to parse.
I was going to say I wonder if it would make sense for the operator to be
or: instead of just
:, but if you read it as “or” or “otherwise”, no code changes needed.
It does, I just have to adjust. I think it works similarly in Excel if I remember correctly, it’s
BOOLEAN (X), FALSE operation, TRUE operation
but instead of “true” there’s an implied “continue the action”.
Has door handle ? “It opens!” : “you can’t open it.”
A Ternary operator makes more sense than a solitary colon. Just saying.
It doesn’t make sense to me in the context of how Gruescript thinks. A line either succeeds, causing its block to continue, or fails, causing its block to fail. An assertion like
has door handle is a whole instruction, not a conditional expression that can be embedded in something else. Success always either completes the block or passes execution to the next line. The : notation is a convenience for “say this if the block fails here”, not an operator that is part of the assertion itself.
(In commands that aren’t assertions, like
bring, the message after the colon is always printed. It’s more like a delimiter than an operator.)
I believe he’s mimicking the instead/continue the action format that Inform 7 rules follow which totally makes sense, I’m just learning a new thing.
I look forward to seeing how ternary operators are handled in the system you develop!
That the tool always reloads the last code when it was left.
That is, right now the system always loads Cloak of Darkness. There’s a very plausible danger to lose progress if someone accidentally hits F5.
I suggest that the system records every last change in an internal state apart from “in browser”. And the systems always recap from there.
Also, it would be awesome if the “Load from browser” button asks “Are you sure you want to load the game saved in the browser memory?”. Because of the same, people accidentally hitting that button by error and losing progress.
The reason why ternary operation works and single colon doesn’t is because having single colon to denote falsehood is contrary to every coding convention out there.
Ternary operation is useful for cases of single condition as opposed to ladder type. But if you really want to insist on ladder type coding, then there’s no problem doing it this way
That is, simply substitute the colon : with ternary op ?:
Try it and see if that helps you to overcome cognitive dissonant.
At the end of the day, it’s your language, so go ahead and do what you want. But I’m letting you know that the reason why you have so much trouble is because you went against convention and that the fix is simply adding a question mark symbol to the colon.
But it’s not denoting falsehood, it’s demarcating a clause, something the colon has been used for about 2300 years.
If I wanted to confuse programmers, I’d make a separator consisting of both parts of a ternary operator, which you cannot split up or use in the same way as a standard ternary operator, and which does something distinct from a ternary operator, but conceptually close enough to give you a false sense of familiarity.
I guess I misunderstood your intention. Never mind, then. Sorry to be a bother.
What IS the “stuff I always recommend people do when launching a new IF system” that they do?
Agreed! This would be super easy to accomplish with localStorage. However, it at LEAST has the “Are you sure you want to reload?” prompt!
I’d cry if I somehow hit the wrong couple of buttons and lost hours of work.
I’m glad you have a local development flow because I couldn’t use the browser for any real work for just this reason.
That’s like saying a DSL written in C looks “like typical C”. Are you sure? I mean, can you tell what Tayruh’s point was?
Well, it’s like saying that the C source code of a DSL implementation looks like typical C, not that the DSL syntax itself looks like C.
tayruh was responding to pdxiv, who said “that’s what web code should look like (in my opinion)”.
And the point was that tayruh did not find it obvious why pdxiv considered this JS code especially exemplary in distinction to usual JS code.
And pdxiv actually agreed with tayruh’s assessment and further explained what he had meant, by following up the “web code” comment with “It’s enjoyable when something is quick to read and that runs quickly without many external dependencies. It’s a work-related injury. I’m used to seeing heavy frameworks”.
And the later, closely related discussion also mentions jQuery.
Got it. I did misunderstand.
I didn’t realize @tayruh was referring to:
that’s what web code should look like
I really thought they were talking about the Gruescript itself. Sorry to everyone involved if it came off as some kind of knee jerk defense of OP. I truly wanted to understand.
that colon/ternary debate is akin to a debate about Fortran and C… separating greater and lesser (with an equal in the middle…) with a colon is the syntax of Fortran’s arithmetic IF:
IF (X) 100,200,300
incidentally, Fortran IS the very first IF programming language…
Best regards from Italy,
Fortran does? I don’t remember it. It’s all about .ne. .ge. and all those dotted operators. If then else endif is the structure. In fact, I don’t know any language that works like you say.
It’s more logical/consistent to say
IF (X) LESS, ,GREATER
Instead of using colon. If that’s the structure you want.
Speaking of which, Level9 has something like this:
Where the variable determines the string displayed, and it can be more than 3 as well. I don’t remember the exact syntax, but I think that’s pretty neat.