command to run any function

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

cheatchki

Supporter ++
Jun 26, 2017
49
1
8
24
So there is probably a SUPER easy way to do this but I want to be able to run a function in a command, this is pretty much so I can do some dev testing with a plugin I have in the works, now I know I could do like

code_language.skript:
function test(player: player):
    message "example function" to {_player}

command /function <text>:
    if arg-1 is "test":
        test(player)

now what I want differs from the above code in two ways

the first,
I want it so it will allow you to plug in the variable as well so if you were to do /function test(cheatchki) It would run the function like that

and second,
I want it so I don't have to define the function within the command as well so

code_language.skript:
function test(player: player):
    message "example function" to {_player}

command /function <text>:
    run arg-1 as a proper function?
 
I'm not certain this is possible. In my testing the blocking point seems to bet the function name itself. I can get it to load properly if I specify the function to be executed, but it doesn't understand the function as a variable the player can choose with the command:
code_language.skript:
function testFunction(n: number, b: text, p: player):
    send "%{_n}%" to {_p}
    send "%{_b}%" to {_p}

#command would look like /function testFunction 1,banana,Wynnevir              
command /function <text> <text>:
    trigger:
        set {_functionname} to arg 1
        set {_ArgumentGiven} to arg 2
        set {_ArgumentList::*} to {_ArgumentGiven} split at ","
        set {_size} to size of {_ArgumentList::*}
        if {_size} = 3:
#The problem is here with the function name variable. the argument variables
#work but it can't understand a variable where the function name should be
            {_functionname}({_ArgumentList::1}, {_ArgumentList::2}, {_ArgumentList::3})
#Putting it in parenthesis, quotes etc also does not work

This however will load, but defeats the point of your goal
code_language.skript:
testFunction({_ArgumentList::1}, {_ArgumentList::2}, {_ArgumentList::3})
 
So there is probably a SUPER easy way to do this but I want to be able to run a function in a command, this is pretty much so I can do some dev testing with a plugin I have in the works, now I know I could do like

code_language.skript:
function test(player: player):
    message "example function" to {_player}

command /function <text>:
    if arg-1 is "test":
        test(player)

now what I want differs from the above code in two ways

the first,
I want it so it will allow you to plug in the variable as well so if you were to do /function test(cheatchki) It would run the function like that

and second,
I want it so I don't have to define the function within the command as well so

code_language.skript:
function test(player: player):
    message "example function" to {_player}

command /function <text>:
    run arg-1 as a proper function?

Perhaps using MundoSK's codeblock expressions may be of use. I personally don't know much about them myself.

code_language.skript:
function test(p: player, t: text) :: text:
    message "%{_t}%" to {_p}

command /function <text> <player> <text>:
    trigger:
        set {_function} to codeblock of function "%arg 1%"
        run codeblock {_function} with arg 2, arg 3
 
Status
Not open for further replies.