Olyno/skent

help with insert into file via files not file.

Misio12320 opened this issue · 3 comments

Hi. Could anyone of developers help me with the code? I see missing expression with files. in the docs of Skent is only [the] (file|dir[ectory]) name of %path% which means only 1 file not all files and I want to make a Skript insert a text from name of file and add it into another file.
My code:

command sounds: #3
    trigger:
        set {_name::*} to file name of file path "/plugins/Gods/"
        loop {_name::*}:
            set {_t::*} to "%loop-value%"
            wait 1 real second
            send {_t::*}
            replace every "_" in {_t::*} with "."
            insert "        ""custom.%{_t::*}%"": {" at line {Line1} of file path "sounds/sounds.json"
            insert "        ""sounds"": [" at line {Line2} of file path "sounds/sounds.json"
            insert "            ""custom/%{_t::*}%""" at line {Line3} of file path "sounds/sounds.json"
            insert "        ]" at line {Line4} of file path "sounds/sounds.json" 
            insert "    }," at line {Line5} of file path "sounds/sounds.json" 
            add 5 to {Line1}, {Line2}, {Line3}, {Line4} and {Line5}

on script load: #1
    set {Line1} to 492
    set {Line2} to 493
    set {Line3} to 494
    set {Line4} to 495
    set {Line5} to 496


#command sounds:
#    trigger:
#        file "sounds/" doesn't exist:
#            create file "sounds"
#        else:
#            stop

It should insert the name of file into sounds.json.
The correct one should look like this:

      "custom.rama.laugh.1": {
        "sounds": [
            "custom/rama.laugh.1"
        ]
    },

not like this:

       "custom.Alert.Notify.Kill.5": {
        "sounds": [
            "custom/<none>"
        ]



        ]

    },
        "custom.Gods": {
        "sounds": [
            "custom/<none>"
        ]

help. This server is running Purpur version git-Purpur-1047 (MC: 1.16.5)
Skript version 2.5.3, Skent version 3.0.0, skUtilities version 0.9.2

Olyno commented

Your code is wrong. There is 3 problems in your code:

  • file path "/plugins/Gods/" gives you only 1 directory or file path, not more. So your set {_name:*} is totally wrong. If you want to get all files and directory paths, then there is an expression to do that.
  • The insert effect is async, meaning it executes the task in parallel. So all your insert will be in a random order.
  • Due to some issues with async stuff and so async effects, I recommand you to use global variable, which should fix the none values.

Fixed a bit;

    trigger:
        set {name::*} to all files of directory path "plugins/Gods/"
        loop {name::*}:
            wait 1 real second
            broadcast {name::*}
            replace every "_" in {name::*} with "."
            insert "        ""custom.%{name::*}%"": {" at line {Line1} of file path "sounds/sounds.json"
            insert "        ""sounds"": [" at line {Line2} of file path "sounds/sounds.json"
            insert "            ""custom/%{name::*}%""" at line {Line3} of file path "sounds/sounds.json"
            insert "        ]" at line {Line4} of file path "sounds/sounds.json" 
            insert "    }," at line {Line5} of file path "sounds/sounds.json" 
            add 5 to {Line1}, {Line2}, {Line3}, {Line4} and {Line5
}

but now its this: ( may I will wait for the async fix.)
"custom/plugins/Gods/Alert_Notify_Kill_5.oga, plugins/Gods/Notify_YouSlainEnemy.oga, plugins/Gods/Notify_Kill_Deicide.oga, plugins/Gods/Alert_Notify_Kill_4.oga, plugins/Gods/Alert_Notify_Kill_3.oga, plugins/Gods/Narrator_Callouts_FirstBlood.oga, plugins/Gods/Notify_Minions_Spawned.oga and plugins/Gods/Alert_Notify_Kill_2.oga"

Olyno commented

I'm closing this issue because I'm not gonna teach how to learn Skript and how use addon syntaxes. A string is not a list, so custom.%{name::*}% not gonna work, and getting all files doesn't mean getting their names, so all files of directory path "plugins/Gods/" will give you a list of path, not a list of name.

You already opened 2 issues about the same project, so have a look inside this issue and the code you did or I gave you there (#20)