Skript: Add Java operators

Created on 25 Feb 2018  路  13Comments  路  Source: SkriptLang/Skript

Hello again.
I know this is going to be priority super omega incredibly very low and is nearly impossible to implement, but I still think it's a good idea.

if 1 = 2 || 2 = 3 || 4 = 4:

if "A" = "B" && "B" = "C":

if "A" = "B" ^ "B" = "B":

I think you get it.
Hope this can be implemented within 20 years!

Thanks!

Most helpful comment

# very clean and nice
if {firstvar} = 4 || {secondvar} = 5 || {thirdvar} = 10:
    # your stuff
# not good as the first one, repeats code
if {firstvar} = 4:
    # your stuff
else if {secondvar} = 5:
    # the same stuff
else if {thirdvar} = 10:
     # 3 times



md5-7e908a9621ebc7690d0a47ab6560919c



# doesn't repeat the same stuff but isn't good
if {firstvar} = 4:
    set {_y} to true
else if {secondvar} = 5:
    set {_y} to true
else if {thirdvar} = 10:
     set {_y} to true
if {_y} is true:
    # your stuff

You can only do that properly using skQuery (which takes 10 years to parse if it's too long).
Let's see:

  • every single language has it, can't be so bad...
  • it's not hard do understand. It allows you to make a cleaner code, which is easier to read.
  • you don't have to use them at all.
  • why english? It's pretty much like using 1 + 1 instead of add 1 to {_n} twice. An operator is made to make things easier, not the opposite.

Maybe a function which does that, then?
set {_a} to and((tool = tnt), (1+1=2))

All 13 comments

its not nearly impossible to implement, skquery has already done it. It's just hard to implement it nicely...

I'm just closing this since it is just an impossible thing with the current parser, and even if it happens it isn't gonna be implemented that way.

I'm working on that, among other things, for another project.

I have no idea how far it will get, but here it is anyway.

NOTE : this is not meant to be merged into Spigot Skript anywhere in the near future, and it is a free time project.

I do not consider adding C-style and and or operators to Skript a good idea. They are not faster to write or easier to read, but trying to guess what they mean is not possible based on only English. We already have enough _weird_ things in Skript, for non-programmers (variable string handling, for example).

I'd like to hear _why_ you think this is a good idea, in case it is some day possible to implement it.

It would be good for the same reasons it is good in any programming language that has them. You can always use else if and nested if to replace || and && ; XOR only takes some more logic to figure out, but not impossible by any means.

# very clean and nice
if {firstvar} = 4 || {secondvar} = 5 || {thirdvar} = 10:
    # your stuff
# not good as the first one, repeats code
if {firstvar} = 4:
    # your stuff
else if {secondvar} = 5:
    # the same stuff
else if {thirdvar} = 10:
     # 3 times



md5-7e908a9621ebc7690d0a47ab6560919c



# doesn't repeat the same stuff but isn't good
if {firstvar} = 4:
    set {_y} to true
else if {secondvar} = 5:
    set {_y} to true
else if {thirdvar} = 10:
     set {_y} to true
if {_y} is true:
    # your stuff

You can only do that properly using skQuery (which takes 10 years to parse if it's too long).
Let's see:

  • every single language has it, can't be so bad...
  • it's not hard do understand. It allows you to make a cleaner code, which is easier to read.
  • you don't have to use them at all.
  • why english? It's pretty much like using 1 + 1 instead of add 1 to {_n} twice. An operator is made to make things easier, not the opposite.

Maybe a function which does that, then?
set {_a} to and((tool = tnt), (1+1=2))

except conditions != expressions

@TrademarkTM I don't see a reason to do this anyways, many Skript conditions support multiple objects, meaning you're able to do:

if {firstvar}, {secondvar} and {thirdvar} are 4 5 or 10:
  # do stuff

The only case where an OR and AND operator would be useful is when you need evaluate more than one condition, which is when you could just use nested ifs.

or if you're worried about too much tabs, one if with indentation and then an inline if or whatever you call them nvm don't kill me probably /sarcasm

@Nicofisi that's actually what I recommend to do, such as this doesn't look as nice:

if arg-1 is player:
  if arg-1 is sprinting:
      #do stuff   

as this does:

arg-1 is player
if arg-1 is sprinting:
  #do stuff

@TrademarkTM you used an and list where I used an or list.

Rewriting it.

Tested it with and:

command /tasd [<text>]:
    trigger:
        send "testing..."
        if 4, 5 and 10 are 4, 5 and 10:
            broadcast "YES"
        else:
            send "Nah"
command /tasd2 [<text>]:
    trigger:
        set {_4} to 4
        set {_5} to 5
        set {_10} to 10
        send "testing..."
        if {_4}, {_5} and {_10} are 4, 5 or 10:
            broadcast "YES"
        else:
            send "Nah"



md5-c94bde05fdbe7fdce57f994d7ee310dc



command /tasd [<text>]:
    trigger:
        send "testing..."
        if 10, 4 and 5 are 4, 5 or 10:
            broadcast "YES"
        else:
            send "Nah"

tasd
They're out of order, but still run return YES.

It would be awesome if Skript allowed you to test multiple conditions with "and" and "or", like
if player is op or player has permission "whatever"

No need to add special characters here. Both with, or without them, this is quite impossible to implement at the moment.

hence why I just closed the issue, it is just not gonna happen anytime soon even if you argue about its usefulness.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Misio12320 picture Misio12320  路  3Comments

GiraffeCubed picture GiraffeCubed  路  3Comments

TheClassic36 picture TheClassic36  路  3Comments

cyanide43 picture cyanide43  路  4Comments

MrScopes picture MrScopes  路  3Comments