Skript

Skript

743k Downloads

On Function Call:

adv333 opened this issue ยท 8 comments

commented

Suggestion

an on Function Call event:

for example:
i have a function "broadcast(message: text)"

so id do:
on function "broadcast" call:
add 1 to {functioncalledamount}

event values:

  • event-returnvalue (optional)
  • event-parameter-1 (optional)
  • event-parameter-2 (optional)

Why?

so id do:
on function "broadcast" call:
add 1 to {functioncalledamount}

obviously this is a very basic example.
and obviously you can just add 1 in the function itself
but it's for code to look cleaner,

for example a quests system, where lets say you must open crates 5 times
and if you use a function to open crates, "openCrate(p: player, crate: text)"
you could just do on function call, for --every single quest type-- in one script file.
making it very clean

Other

No response

Agreement

  • I have read the guidelines above and affirm I am following them with this suggestion.
commented

Could be handy to let Skript users make 'API' endpoints to listen to custom events of some sorts.

commented
on function "broadcast" call:
add 1 to {functioncalledamount}

I can't see anything you can do with this that you couldn't do by just putting your code inside the function itself.

commented
on function "broadcast" call:
add 1 to {functioncalledamount}

I can't see anything you can do with this that you couldn't do by just putting your code inside the function itself.

Would be great if you had the attention span to read the entire post

commented

Not commenting on the usefulness or lack of here, but this event does existing in skript internally already, however it is disabled due to performance concerns and must be enabled by (and syntax implemented by) an addon.

commented

Would be great if you had the attention span to read the entire post

Hello, please try to behave politely on the issue tracker.

In case it wasn't clear, which I suppose it may not have been, listening to a specific function by its literal name as you suggested will not create any new possibilities that you couldn't achieve by putting your code into the function itself.

To use the example you gave:

function openCrate(p: player, crate: text):
    # A

on function "openCrate" call:
    # B

would be functionally identical to just doing

function openCrate(p: player, crate: text):
    # A
    # B

or, if that's not to your liking,

function openCrate(p: player, crate: text):
    # A
    myOtherFunction()

function myOtherFunction():
    # B
commented

Would be great if you had the attention span to read the entire post

Hello, please try to behave politely on the issue tracker.

In case it wasn't clear, which I suppose it may not have been, listening to a specific function by its literal name as you suggested will not create any new possibilities that you couldn't achieve by putting your code into the function itself.

To use the example you gave:

function openCrate(p: player, crate: text):
    # A

on function "openCrate" call:
    # B

would be functionally identical to just doing

function openCrate(p: player, crate: text):
    # A
    # B

or, if that's not to your liking,

function openCrate(p: player, crate: text):
    # A
    myOtherFunction()

function myOtherFunction():
    # B

Hello, I already addressed this in the post itself in case you went back to tiktok after reading the first line.

It's for cleaner code.

Imagine if you had a quests system, and you want to add to the progress. Lets say open 5 crates, deal 500 magic damage, complete 5 challenges, etc that doesnt rely on bukkit events.

Instead of going to the respective files and functions and then adding the function to add progress you could just do it all in one file.

This is not just about quests, there are many things that can be simplified to be more convenient and cleaner looking by adding this simple feature.

commented

Hey, there's no need to insult someone because they disagree with your suggestion.
Sovde already provided a valid reason as to why this hasn't been added already. Furthermore, I believe this will encourage messier code that's harder to debug.

commented

It's for cleaner code.

Imagine if you had a quests system, and you want to add to the progress. Lets say open 5 crates, deal 500 magic damage, complete 5 challenges, etc that doesnt rely on bukkit events.

Instead of going to the respective files and functions and then adding the function to add progress you could just do it all in one file.

This is not just about quests, there are many things that can be simplified to be more convenient and cleaner looking by adding this simple feature.

I don't think this would actually result in cleaner code, as calling the function now has side effects you can't identify by looking at the function itself. You could use skript-reflect to make a custom event, or use the dynamic function call capabilities that are being worked on in #6713.