#(Haise) List Sorting
60 messages · Page 1 of 1 (latest)
(Haise) List Sorting
Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.
You can block this bot if you don't want to see these messages, I won't mind.
<@&525394568410038282>
!t sort_by_value
you have some object hacking there
Your question seems to be an XY Problem - you're asking about your attempted solution rather than your original problem.
Read in detail about the XY Problem here: http://xyproblem.info/
For an example of an XY Problem we've seen in Denizen, the question "how do I make an event for when a flag expires" has no answer, but the same question asked with full background detail will be something more like "I have this script: [LINK HERE], which sets a 3 minute cooldown flag on a player for when they use an ability. I want the player to be notified when the cooldown completes - how do I do this?" which we can then answer quite effectively (in this example, all that was needed was a simple wait command, no events or flag-listening or anything).
Why are you doing that?
for like a playershop system putting all items inside a list and each item is a list that contains the price item etc so like wanted to sort the items by price from highest to lowest etc
also how would this work with lists like inside of the other lists
It sounds like you want maps, not lists
what would you even put in the value or is it like choose the first value? or smth
oh you mean it would be better if did it in maps instead?
Yes, have maps for all of the items in your shop, probably using a data script
!l data script
Data script containers are generic script containers for information that will be referenced by other scripts.
No part of a 'data' script container is ever run as commands.
There are no required keys.
Generally, data is read using the !tag ScriptTag.data_key tag.
data_script_name:
type: data
# Your data here
some_key: some value
some_list_key:
- some list value
some_map_key:
some_subkey: some value
Script Container System
That way you can easily configure stuff in, and then read them in your shop script
Oh tho the resson i used flags was like because players were able to list their items for sale so like when a player lists it for sale i would put it in a flag can i modifiy a datascript like flags? with player items?
I see, still - you'd probably want a flag map with keys for each bit of information
Tho would it be possible to sort a flag map in the way i descriped above like depending on their price etc.
yes
Oh what is like the synatx to sort a flag map like an example?
that heavily depends on the data structure
Hm for something like this?
- definemap shopdata:
item:
quantity:
price:```
and like i wanna sort them by price
!t map.sort_by_value
Returns a copy of the map, sorted alphanumerically by the value under each key.
Optionally, specify a tag to apply to the value.
To sort by key, use !tag MapTag.get_subset with list sort tags, like 'map.get_subset[map.keys.sort_by_value[...]]'.
This also lets you apply list filters or similar to the keyset.
To apply a '.parse' to the values, use !tag ListTag.map_with, like 'map.keys.map_with[map.values.parse[...]]'
MapTag
# Narrates a map of [a=1;b=2;c=3]
- narrate <map[c=3;a=1;b=2].sort_by_value>
# Narrates a map of [c=3;b=2;a=1]
- narrate <map[c=3;a=1;b=2].sort_by_value[mul[-1]]>
you can sort the map directly
Your question seems to be an XY Problem - you're asking about your attempted solution rather than your original problem.
Read in detail about the XY Problem here: http://xyproblem.info/
For an example of an XY Problem we've seen in Denizen, the question "how do I make an event for when a flag expires" has no answer, but the same question asked with full background detail will be something more like "I have this script: [LINK HERE], which sets a 3 minute cooldown flag on a player for when they use an ability. I want the player to be notified when the cooldown completes - how do I do this?" which we can then answer quite effectively (in this example, all that was needed was a simple wait command, no events or flag-listening or anything).
uh? i dont think that works? because this map is gonna be like a flag map not actual map? and there gonna be multiple of it inside the same flag thats the sorting we are talking about
this is a map
do you save it inside a list oder another map
(I'd recommend a list of maps for that)
Yea thats what i'm trying to make right now
Thats why trying to figure out how thats gonna work practiacly
!t list.sort_by_value
Returns a copy of the list, sorted alphanumerically.
Rather than sorting based on the item itself, it sorts based on a tag attribute read from within the object being read.
For example, you might sort a list of players based on their names, via .sort_by_value[name] on the list of valid players.
ListTag
!t list.sort_by_number
Returns a copy of the list, sorted such that the lower numbers appear first, and the higher numbers appear last.
Rather than sorting based on the item itself, it sorts based on a tag attribute read from within the object being read.
For example, you might sort a list of players based on the amount of money they have, via .sort_by_number[money] on the list of valid players.
Non-numerical input is considered an error, and the result is not guaranteed.
ListTag
Returns the object value at the specified key.
If a list is given as input, returns a list of values.
ObjectTag
# Narrates '2'
- narrate <map[a=1;b=2;c=3].get[b]>
# Demonstrates that list input gives list output - narrates '2' then '3'
- foreach <map[a=1;b=2;c=3].get[b|c]> as:value:
- narrate "One of the values is <[value]>"
Ah yea ic and if i like put the maps inside a flag it will be a list of maps like - flag server maplist:->:<[definemapname]>
ye
Thread closed as resolved.
oh sorry for reopening but i think this synatx is wrong it keep returning null for me
Thread was manually reopened by @reef basalt.