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
For each index & value loop. #6562
base: dev/feature
Are you sure you want to change the base?
Conversation
…oday only!) method.
Version thingy. Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com>
Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com>
I'm still not sure about this feature. I think the existing system works well, and I think there's a benefit in just having a single simple way to loop things. |
I'm happy with that too, but if people decide we need something I am in favour of this being it. |
Pretty much every loop I've written recently has looked like this, when more than one nested loop is involved. loop 10 times:
set {_counter} to loop-value
loop {_something::*}:
set {_value} to loop-value-2 It's just so much easier to keep track of what's what, helps avoid off-by-one errors in the loop-value-x, and being able to have descriptive names makes the code way more legible. That said, this code is perfectly fine to keep, but I feel like this addition would be valuable in that it would remove the dead weight of those set lines. |
I have a vague memory that there are some cases where you can't use the |
Yes, any section that resets the events (EffSecSpawn, for example) means you have to put the loop-value into a var in order to access it in the section, since when it runs isn't guaranteed. |
Description
Having talked with Ayham about my concerns, I've opened this as an alternative proposal to Ayham's loop PR #6053.
This will be in draft until we reach a consensus about which approach to adopt.
Ayham's syntax was:
I'm not very happy about changing or adding to the existing
loop ...
section syntax, because it's such an old and established thing, and I worried that the syntax was becoming a bit long and difficult to interpret.I also thought this feature might be a good opportunity to mimic for-each loops from other languages like Java and Python.
My alternative for-each is specifically designed for dealing with key<->value maps,
by storing the index and value in reference variables.
It also extends the existing
SecLoop
so all loop behaviour is available as normal.The syntax is (note ~object specifically accepts a variable):
Note: while I wanted to do
for A, B in ...
(like Python) I was concerned that Skript might mistake this forfor <list of A, B> in ...
rather thanfor <A>, <B> in ...
.Note: this is registered as an experimental feature, toggled with
using for each loops
.Target Minecraft Versions: any
Requirements: #6551, #6552
Related Issues: #6052, #6053