#(Haise) List Sorting

60 messages · Page 1 of 1 (latest)

reef basalt
#

Is there a way to sort lists inside of a list

Like for example <list[<list[421|Example]><list[523|Example]><list[752|Example]><list[840|Example]>]>

Like is there a way to sort the lists inside based on their first element for example making the list with the highest number on the first element is the first list

brisk geyserBOT
#

(Haise) List Sorting

brisk geyserBOT
#

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>

stiff tapirBOT
rapid prism
#

you have some object hacking there

glacial dune
#

But ^

#

!xy

stiff tapirBOT
# glacial dune !xy
Info: xy

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).

glacial dune
#

Why are you doing that?

reef basalt
# glacial dune 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

reef basalt
# stiff tapir

also how would this work with lists like inside of the other lists

glacial dune
reef basalt
#

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?

glacial dune
#

Yes, have maps for all of the items in your shop, probably using a data script

#

!l data script

stiff tapirBOT
# glacial dune !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


Group

Script Container System

glacial dune
#

That way you can easily configure stuff in, and then read them in your shop script

reef basalt
#

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?

glacial dune
#

I see, still - you'd probably want a flag map with keys for each bit of information

reef basalt
reef basalt
#

Oh what is like the synatx to sort a flag map like an example?

charred mist
reef basalt
#

Hm for something like this?

- definemap shopdata:
    item:
    quantity:
    price:```
#

and like i wanna sort them by price

glass wave
#

!t map.sort_by_value

stiff tapirBOT
# glass wave !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[...]]'

Returns

MapTag

Examples
# 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]]>
glass wave
#

you can sort the map directly

stiff tapirBOT
#
Info: xy

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).

foggy iceBOT
reef basalt
# glass wave you can sort the map directly

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

charred mist
#

do you save it inside a list oder another map

#

(I'd recommend a list of maps for that)

reef basalt
#

Yea thats what i'm trying to make right now

#

Thats why trying to figure out how thats gonna work practiacly

charred mist
#

!t list.sort_by_value

stiff tapirBOT
# charred mist !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.

Returns

ListTag

charred mist
#

!t list.sort_by_number

stiff tapirBOT
# charred mist !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.

Returns

ListTag

charred mist
#

<[list_of_maps].sort_by_number[get[price]]>

#

something like that

#

!t maptag.get

stiff tapirBOT
# charred mist !t maptag.get

Returns the object value at the specified key.
If a list is given as input, returns a list of values.

Returns

ObjectTag

Examples
# 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]>"
reef basalt
#

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]>

charred mist
#

ye

reef basalt
#

and then i get them out of the flag right with the number sort

#

thank you so much

pallid lodgeBOT
#
Resolved

Thread closed as resolved.

reef basalt
pallid lodgeBOT
#
Thread Reopened

Thread was manually reopened by @reef basalt.