Coder Social home page Coder Social logo

Comments (2)

cgytrus avatar cgytrus commented on August 14, 2024

Update: figured out a bit more about this
there are issues with logical operators and conditional statements that are kinda probably related to each other
about logical operators:
this code:

asat(@e) {
    if('block ~ ~ ~ air' && 'block ~ ~-1~ air' || 'block ^ ^ ^ air' && 'block ^ ^ ^1 air') {
        /say huh??
    }
}

compiles as

execute as @e at @s if block ~ ~ ~ air if block ~ ~-1~ air if block ^ ^ ^1 air run say huh??
execute as @e at @s if block ^ ^ ^ air run say huh??

when it actually should be

execute as @e at @s if block ~ ~ ~ air if block ~ ~-1~ air run say huh??
execute as @e at @s if block ^ ^ ^ air if block ^ ^ ^1 air run say huh??

from this you can see, that it sorts the operators (cond1 && cond2 || cond3 && cond4) by their priority (cond1 && cond2 && cond4 || cond3) when it actually should take the &&(and) conditions in one execute command and ||(or) in multiple without sorting them
a possible solution for this would be to not sort the conditions, but apply multiple "passes", so that one pass handles &&s, then the next one ||s etc.

now about conditional operators (if/else):
this code:

asat(@e) {
    if('block ~ ~ ~ air' && 'block ~ ~-1 ~ air) {
        /say cond1
    } else {
        /say cond2
    }
}

compiles as

execute as @e at @s if block ~ ~ ~ air if block ~ ~-1 ~ air run say cond1
execute as @e at @s unless block ~ ~ ~ air unless block ~ ~-1 ~ air run say cond2

when it actually should be

execute as @e at @s if block ~ ~ ~ air if block ~ ~-1 ~ air run say cond1
execute as @e at @s unless block ~ ~ ~ air run say cond2
execute as @e at @s unless block ~ ~-1 ~ air run say cond2

from this you can see, that the else statement only inverts the conditions, when it also should revert the logical operators, so cond1 && cond2 becomes !cond1 && !cond2 but it actually should become !cond1 || !cond2

hope this update helps you to fix these!

from mcscript.

Stevertus avatar Stevertus commented on August 14, 2024

Thanks for posting this. I often noticed that the boolean parsing is not quite right. And actually made a way better implementation of it in objd. But in fact mcscript was never supposed to do this that way. It should give a slight syntax variation of the minecraft commands and in the process it also inherited the problems with if and unless.

I understand that one might expect this behaving differently, but I honestly have not the time and motivation to rewrite anything to fix this big issue.

from mcscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.