urbanyoung / Phasor

Phasor is a server extension for Halo PC which focuses on giving the end-user the ability to deeply customize gameplay. Phasor does this via its scripting system, which uses the Lua language. Scripters are able to react to and change many different aspects of the game.
MIT License
19 stars 9 forks source link

Call function from another script #43

Open chrisk123999 opened 11 years ago

chrisk123999 commented 11 years ago

[03:18] =CE= Chris [Equal]: think you could add sommething to that would let us call a function from another currently running script? but isn't done with an include [03:18] =CE= Chris [Equal]: cause my script makes it's own admin system [03:18] =CE= Chris [Equal]: but I'd like a way to let other scripts interface with it somehow [03:18] Oxide: Nuggets has requested a similar feature - overriding Phasor funcs for all scripts [03:19] =CE= Chris [Equal]: I mostly need it just so I can have one script check my admin script to see if they're allowed to do certain commands [03:20] Oxide: Yeah, I do plan to add something like that (yours and nuggets' requests are effectively the same thng) [03:20] =CE= Chris [Equal]: however mine would be to call a function in it, not just simply replace a command

urbanyoung commented 11 years ago

(Effectively) the same as https://github.com/urbanyoung/Phasor/issues/42

chrisk123999 commented 11 years ago

Not really, as that one would only be saving specific info, I want to make it run stuff in the other script.

urbanyoung commented 11 years ago

From an implementation point-of-view they're pretty much the same. In his request you'd do something like override("isadmin", "my_isadmin") and yours would be register("isadmin", "my_isadmin")

chrisk123999 commented 11 years ago

But what if I want to do something that doesn't replace a phasor function? As I'd like to be able to call functions from my stat tracker in my admin script.

urbanyoung commented 11 years ago

Oh right, yeah it'd be register("mynewfunc")

chrisk123999 commented 11 years ago

How about instead of having the script register it's own function, let the other script simply called the script name and function. So it would be more like: local some_var = callscript("scriptName", "functionName")

This would allow me to make scripts that extend the functionality of other scripts. This would allow me to add extra info to my admin script by reading the already collected stats from the stat tracker script. This would also most likely need another function to check if the script is loaded in the first place.

urbanyoung commented 11 years ago

Yeah that could work, I'd need to add another function where scripts can specify their name, but that's not really an issue. So, like

function OnScriptLoad()
   setname("myAdminScript")
end

... other script ...
callscript("myAdminScript", "someFunction")
chrisk123999 commented 11 years ago

That sounds good.

twhitcomb commented 11 years ago

My suggestion was meant for any function you've written in Lua to be able to be saved to Phasor; I just used overriding a Phasor function as an example.

Edit: Read this issue before reading the updated comments on my own; apologies for the redundancy.