Stevertus / mcscript

A programming language for Minecraft Vanilla
https://mcscript.stevertus.com
MIT License
233 stars 16 forks source link

Use unless keyword as a negation #22

Closed TheBrenny closed 3 years ago

TheBrenny commented 4 years ago

When comparing values against eachother, there's no way to test if two items are NOT EQUAL, other than converting the comparison check to a stringified version then negating it with an exclamation mark.

I'm proposing that there should be an unless keyword which functions identically to the if keyword, except instead of inserting if it inserts unless. Further, the contract between these two keywords should be so that if(!comparison) === unless(comparison) and if(comparison) === unless(!comparison).

This keyword makes mcscript more consistent with Minecraft's /execute command as well!

A use case for this is for checking inequality between two variables. This only works using one of two workarounds which make the pre- and post-compiled code both too large for a simple task:

// Setup
var selected @s = 1 // actually something more legitimate
var current @s = 0 // again, something more legitimate

// These don't work!
if(selected @s != current @s) {}
if(!'selected @s = current @s') {}
if(selected @s <> current @s) {}

// These are the workarounds
if(selected @s < current @s) {} // step 1
if(selected @s > current @s {} // step 2
// or
if(selected @s = current @s) {} else {}

I'd throw my hand up to help out, but 1) I've only stumbled upon this project and haven't fully looked at it, and 2) I'm already too deep in my rabbit hole of things which lead me here...

Love your work though! ๐Ÿ™Œ๐Ÿฑโ€๐Ÿ

Stevertus commented 3 years ago

added in v0.2.3