List Variable Is Empty Suggestion
MissingReports opened this issue ยท 5 comments
Suggestion
List variables are abit weird, you can't create an empty list since "empty" lists are just non existing lists. You check if a list is empty by using if {_list::*} is set
, I feel like it should be if {_list::*} is empty
which wouldn't error but it will always fail or succeed, I can't remember
List variables also can be a list or a map (key-value pair), something like this add "Hello" to {_list::*} <-- list
and set {_list::hello} <-- map
This creates alot of confusion since {_list::hello} and {_list::*} are both one but one value is a list and the other is a map
add "test" to {_list::*}
set {_list::blah} to "blah"
loop {_list::*}:
broadcast loop-value
There should be a way to identify lists from maps or at least separate both
This one isn't really needed but it'd be nice to have which is streams to filter (this one exists), map (edit a list without loops), etc
There should be a proper way to insert in a list, maybe something like this insert %objects% in[to] %objects% at %integer%
All of that isn't really needed but it'd be nice to have. And maybe make it so you can old list mechanics through the config to not break code
Why?
This would make lists not confusing to new skripters
Other
No response
Agreement
- I have read the guidelines above and affirm I am following them with this suggestion.
I think it might be nice to have is empty
for lists, I was always disappointed when that didn't work how I wanted it to.
I had made such suggestion in #5435
I had made such suggestion in #5435
Your issue doesn't mention list emptiness, just strings. If it did I could close this in favour of yours.
Oh, I was taking the consideration of the condition as both holds a somewhat identical keypoint, so ooops disregard.
I think you're a little confused on how lists work. When you say they're sometimes a list and sometimes a map, they're really just always maps. {_list::hello} and {_list::*}
are both variables, but one is a single element ({_list::hello}
) and the other is multiple elements ({_list::*}
, which is all the values in the _list list.)
So there's no difference between lists and "maps", they're the same. add "test" to {_list::*}
when {_list::*}
is empty is exactly the same as set {_list::1} to "test"
.
As far as "insert", you can use some math to do that pretty easily, assuming you're using numeric indices. If you're not, then insertion is a bit useless anyway.
is empty
is for checking if inventories, slots, or strings are empty. I'm not sure if it would be feasible to extend that to lists, and I don't think it needs to be done since is set
works quite well.