Skript: loop 0 times will loop 2 times.

Created on 8 Jul 2018  路  26Comments  路  Source: SkriptLang/Skript

Skript: dev36

on script load:
    loop 0 times:
        broadcast "loop!"

It loops twice regardless of event, that's all you need to know.

I'm going to work on fixing this, just putting it here in case I forget.

bug completed low

Most helpful comment

Ok, this whole thing is a bug. Looping 0 times should do nothing. Also, looping negative amount of times should not be allowed at all. It should error if hardcoded, and do nothing otherwise.

All 26 comments

Because it returns 1 and 0 if you didn't check ^^

This isn't the numbers between syntax...

This should not be a thing. If it's based off a variable, and it was 0 then the code would run twice ruining what was actually expected of the syntax.

Don't you know X times returns list of numbers between 1 and X? So 0 times means numbers between 1 and 0 so it is 1 and 0.

yeah -2 times = 1, 0, -1 and -2

Speaking as a less coding-language savvy person, i agree that 0 times should not loop at all, because that's what i'd expect skript to do without losing another thought to it. Trying to speak for people of my lesser skill level here.

@TheLimeGlass it is actually the numbers between syntax, or at least pretty much the same logic if you look at the class of this syntax.

Either way, I do agree that this is a pretty strange behaviour that should be fixed.

what happens with negative numbers?

what happens with negative numbers

seems to be what @Blueyescat and @Snow-Pyon said

command /test:
        trigger:
                loop -5 times:
                        broadcast "%loop-number%"
> test

Anything less than or equal to 0 just adds 2.

Anything less than or equal to 0 just adds 2.

can you elaborate?

It is really simple... -5 times is equal to numbers between 1 and -5.

@blueyescat I know but I don't get what LimeGlass said lol

You know but Lime didn't understand

Any number that is less than or equal to 0 will add two numbers, that's hard to understand?

If it's loop -5 times it doesn't stop after looping -5 times it keeps going two more numbers.

I see potential here.
If somebody uses loop 0 times, make the plugin delete all of the server's .sk files.
And if somebody uses loop -1 times or any lower number, make all the actions in the loop reverse logically. And delete their files anyway.

@TheLimeGlass hmm now I get what you meant but that's a rather less intuitive way to explain it I have to say lol

You mean -5 times should be -1, -2, -3, -4 and -5, without 1, 0?
That is how it works currently as it is equal to numbers between 1 and -5.

You can just make the times expression returns null if the number is smaller than 1.

No -5 to -1 is how it should operate, just like everyone would expect... and I fixed the between numbers syntax awhile ago to work any way you input it, it used to just return null. For example numbers between 1 and 8 should work, and numbers between 8 and 1 will give you the opposite.

You can just make the times expression returns null if the number is smaller than 1.

Yes, that would be the solution

loop -5 times is not English, the times expression is made to provide more readable loop codes. It is not an alternative for the numbers between expression. If you want negative numbers, use the numbers between expression.

I completely agree with @Blueyescat, I feel like parsing should straight up fail if you try to do %number% times with a number less than one. It simply doesn't make sense and defeats the point of the expression (to make code more readable since it's essentially a numbers between alias).

it may make the most sense to split the two up to prevent issues like this

If a variable is used in the contex, then a condition statement will be needed...

if {_x-coordinate} is less than or equal to 0:
    loop numbers between {_x-coordinate} and 0:
        forcedFunction(loop-number)
else:
    loop {_x-coordinate} times:
        forcedFunction(loop-number)

This is ugly... Why wouldn't you just add this simple fix...

loop {_x-coordinate} times:
    #code that doesn't need to be split

It makes everything simpler and easier...

And it said -5 not -5 + 2 or -7. It makes no sense how it currently operates.

Going to pull request as I stated when I get time, and provide examples in a logical situation.

@TheLimeGlass I have no idea what you're proposing at the moment. You want loop -5 times to loop 5 times? Or do what?

loop <negative number> times: should error at parse time if the expression is a negative number literal, and in case of non-literals simply do nothing when executed

No, you don't understand. It will loop -5 times with the loop-number being a negative which is what is needed and expected. 0 should be the axis in which the maximum value reaches if the number becomes a negative, and not two extra added numbers. It's a simple fix, and would best show in coordinate calculations, since clearly coordinates can be negative.

There is no point in having it return null unless the value equals 0 (which also needs to be addressed), because there is functionality that is needed to be corrected.

@TheLimeGlass read this for a few more times
image

Ok, this whole thing is a bug. Looping 0 times should do nothing. Also, looping negative amount of times should not be allowed at all. It should error if hardcoded, and do nothing otherwise.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

ghost picture ghost  路  3Comments

Snow-Pyon picture Snow-Pyon  路  4Comments

Romitou picture Romitou  路  3Comments

wohahobg picture wohahobg  路  3Comments