Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Function Call: #7049

Closed
1 task done
adv333 opened this issue Sep 7, 2024 · 8 comments
Closed
1 task done

On Function Call: #7049

adv333 opened this issue Sep 7, 2024 · 8 comments

Comments

@adv333
Copy link

adv333 commented Sep 7, 2024

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.
@Moderocky
Copy link
Member

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.

@Mwexim
Copy link
Contributor

Mwexim commented Sep 7, 2024

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

@adv333

This comment was marked as abuse.

@sovdeeth
Copy link
Member

sovdeeth commented Sep 7, 2024

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.

@Moderocky
Copy link
Member

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

@adv333

This comment was marked as abuse.

@TenFont
Copy link
Contributor

TenFont commented Sep 7, 2024

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.

@Pikachu920
Copy link
Member

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.

@Pikachu920 Pikachu920 closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants