@Phipsz: I'c. using the substitution facility for this was the missing link. Thanks for clarifying.
@YorrickVander: Pardon me, but still having difficulties fully getting what you mean here... By adding a Lua file to any addon, all the code which is inside the Lua file is executed on load (which normally is at the time the game starts). So if you write the following code:
Code: Select all
function foo()
-- do whatever you wanna do here
end
foo()
your function foo will be executed on load directly.
If you want to execute that upon some other trigger, you have different possibilities to do so. One example was given by Phipsz. Another example is to execute the function/code on a timely manner or upon certain gamestates, in which case you have the onUpdate()-function you could use. The onUpdate() function is executed every frame, so you could implement the trigger condition like:
Code: Select all
function onUpdate()
-- if I'm in a ship and being attacked by drones then
foo()
-- or alternatively to call ur function every 200 frames
int count = 0
function onUpdate()
if count == 200
foo()
count = 0
else
count = count + 1
end
end
function init()
-- create your frame
SetScript(myFrame, "onUpdate", onUpdate)
Do u mean that atm you lack the possibilitiy to execute scripts upon keypresses directly? Aka you would like to execute your function foo() when you press "k" for instance?