Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why aren't conditions boolean expressions? #2207

Open
TrademarkTM opened this issue Jun 27, 2019 · 16 comments
Open

Why aren't conditions boolean expressions? #2207

TrademarkTM opened this issue Jun 27, 2019 · 16 comments
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something. PR available Issues which have a yet-to-be merged PR resolving it priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).

Comments

@TrademarkTM
Copy link

TrademarkTM commented Jun 27, 2019

Question

I'm not sure if this has been discussed already, but why can't conditions be used as boolean expressions? Would it be too hard to implement?

For example:
send "Can you fly? %player can fly%" to player

Also, ifs could support booleans, for example if %booleans%. Multiple booleans could work like true, false and true (&&) and true, false or true (||).

So, something like this would be valid:

if player can fly and player is alive:
    send "both"
else:
    send "nope"
if player can fly and player's fly mode: # optional (or not) player's fly mode = true here
    send "both"
else:
    send "nope"

Reversing booleans might also be useful:

set player's fly mode to !(player's fly mode)
send "Your new fly mode is %player's fly mode%!"

These are just ideas.
My guess is that it's either too hard to add or it destroys parse time, but I don't think it's that bad for readability.

@Moderocky
Copy link
Member

I would definitely support this if it was possible to add. Looks really useful.

@jaylawl
Copy link
Contributor

jaylawl commented Jun 28, 2019

For reversing booleans, maybe some sort of toggle effect might do the trick:

toggle %boolean%

This would be more in the spirit of skript, athough not as universally applicable as !(player's fly mode).
How about:

reversed %boolean%
inverse of %boolean% // %boolean%'s inverse

as an additional expresseion

@Matocolotoe
Copy link
Contributor

Seems like loop-number = 5 isn't a boolean either

@Moderocky
Copy link
Member

Seems like loop-number = 5 isn't a boolean either

It's currently a condition, EWS is proposing that all conditions basically become expressions that return booleans, and the condition then becomes if %boolean%: (allowing you to use a lot more there.)

For reversing booleans, maybe some sort of toggle effect might do the trick:

toggle %boolean%

This would be more in the spirit of skript, athough not as universally applicable as !(player's fly mode).
How about:

reversed %boolean%
inverse of %boolean% // %boolean%'s inverse

as an additional expresseion

I'd agree that we would need more english-sounding ones like those. But I would definitely like to keep !%boolean% since that's faster to type and makes sense to people with experience in many coding languages.

@Matocolotoe
Copy link
Contributor

I'd agree that we would need more english-sounding ones like those. But I would definitely like to keep !%boolean% since that's faster to type and makes sense to people with experience in many coding languages.

And Skript already supports != notation

@jaylawl
Copy link
Contributor

jaylawl commented Jun 28, 2019

@Moderocky yes, that's faster to type, however imo there should be a clear line between skript and skript-mirror-esque syntax.

@TheBentoBox TheBentoBox added enhancement Feature request, an issue about something that could be improved, or a PR improving something. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation). labels Jul 31, 2019
@TheBentoBox
Copy link
Member

This would be a really useful change long-term so I'll set it higher priority to hopefully encourage someone getting to it sooner.

@Anarchick
Copy link

#1468

@Skylyxx
Copy link

Skylyxx commented Apr 28, 2021

I think is still open because the PR isn't merged

@FranKusmiruk
Copy link
Member

why is this still open

the PR hasn't been merged yet. I am also not really fond of merging that PR as things are right now, if we merge that PR it means users will be able to use conditions as expressions which has always been a dumb limitation in Skript, but it is there mainly because there's no good way to make the pattern look correct, grammatically speaking. See the following example:

set {_fly-state} to player can fly

this looks indeed weird to the eyes, hence why it was limited but this can be simply solved by adding the prefix whether to the condition. Now, the way I was thinking to do this was to create a new type of expression, a ConditionalExpression, which would basically be any expression that returns a boolean and by making this expression we could make an expression like whether %booleans% and call it a day. However, as you can see I never got to make this as I became inactive and to be honest, I prefer to have an ugly pattern rather than limit the capability of Skript so I might as well just merge that PR unless someone does make this change, as it can be done in the future instead.

@AyhamAl-Ali
Copy link
Member

this looks indeed weird to the eyes, hence why it was limited but this can be simply solved by adding the prefix whether to the condition. Now, the way I was thinking to do this was to create a new type of expression, a ConditionalExpression, which would basically be any expression that returns a boolean and by making this expression we could make an expression like whether %booleans% and call it a day. However, as you can see I never got to make this as I became inactive and to be honest, I prefer to have an ugly pattern rather than limit the capability of Skript so I might as well just merge that PR unless someone does make this change, as it can be done in the future instead.

The whole idea of having booleans as expressions is just great and make things much easier in many cases.

However, the weird looking thing is kinda true but it isn't a big deal because even in other languages they look kinda similar set {_hasPerm} to player has permission "perm" same as player.hasPermission("perm") but yea the to part makes it look weird :D

As you said, as for now IMO, it is not a big deal and maybe later someone will make a PR for this.

@TPGamesNL
Copy link
Member

IMO it'd be better to deal with the syntax choice before it's merged, otherwise it might take too long and people will have gotten used to the syntax. The problem with using whether %condition% is that, when being used in ExpressionList, it'll be required as well (e.g. if whether player can fly and whether player is alive) (unless we can find a way around this)

@Mwexim
Copy link

Mwexim commented Apr 28, 2021

IMO it'd be better to deal with the syntax choice before it's merged, otherwise it might take too long and people will have gotten used to the syntax. The problem with using whether %condition% is that, when being used in ExpressionList, it'll be required as well (e.g. if whether player can fly and whether player is alive) (unless we can find a way around this)

Again, this is not necessary!

If you want me to explain it better, I'll provide you with the full implementation of ConditionalExpression in skript-parser.

Basically, conditional expressions cannot be used unless specified.

  • if %=boolean% (You can use conditions here)
    e.g. if player can fly
  • set %objects% to %objects% (You cannot use conditions here except when using whether, notice that there is no '=')
    e.g. set {var} to whether player can fly
  • whether %=boolean% would be used to use conditions as 'normal' expressions

Some more examples;

  • %=boolean% and %=boolean% (and operator)
  • not %=boolean%

@TPGamesNL
Copy link
Member

That would be an option, but since the number of syntaxes where that'd be necessary is small, wouldn't it be easier to use an all-matching regex instead of an extra type flag?

@Mwexim
Copy link

Mwexim commented Apr 29, 2021

That would be an option, but since the number of syntaxes where that'd be necessary is small, wouldn't it be easier to use an all-matching regex instead of an extra type flag?

An all matching regex is far less productive:

  • It tells you nothing about what actually needs to be there
  • An additional type flag is very easy to add if you would use an implementation similar to that of skript-parser. I forgot how the PR was made, so I'd have to look into it to see how you could implement this in Skript.
  • It will be very easy for addon developers to create their own variants, instead of forcing them to use regexes as well.

This is not really 'an option' anymore, it is a design choice. This issue should be discussed thoroughly as the PR is not ready yet to be merged, especially given that the community is divided about the matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something. PR available Issues which have a yet-to-be merged PR resolving it priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).
Projects
None yet
Development

No branches or pull requests

13 participants