Sadly I have bad news: I don't think there's any way to figure out which sprite has called the thinkproc. Someone can correct me on this one if I'm wrong.
Use
event.sprite and you can figure out what sprite triggered their
sprite.thinkproc[] event.
As far as passing arguments instead of globals everywhere, that'd be nice, although I can't see it being possible in VC. In Lua, you can could create a local scope to keep other code from modifying the sprite variables, like this:
do
local birds = {}
function moveBird()
if not birds[event.sprite] then
-- First time using this sprite.
-- Create new birds table entry.
-- ...
else
-- Bird's entry exists, update it.
-- ...
end
end
end
local spr = v3.GetSprite()
v3.sprite.image[spr] = birdFrame[1]
v3.sprite.thinkproc[spr] = moveBird
Really
sprite.thinkproc[] should probably be using function values instead of names of global functions. That'll probably change later. But as you can see, you can create a private table for your sprite management, and then use
event.sprite to index it, which should work for now.
EDIT:
Also, in Lua, making the engine keep track of extra arguments to functions is completely unnecessary, since you can create anonymous functions with upvalues, and basically use them to call higher-arg functions:
function f(a, b, c)
return a + b + c
end
local g = function(a)
return function()
return f(a, 1, 1)
end
end
local h = g(2)
print(h())
-- More complex example
function methodPointer(self, meth)
return function(...)
return self[meth](self, ...)
end
end
Monster = {}
function Monster.new(name)
local t = { name = name }
for k, v in pairs(Monster) do
t[k] = v
end
return t
end
function Monster:roar()
print('The ' .. self.name .. ' roars!')
self:roar()
end
monster = { Monster.new('Slime'), Monster.new('Bat') }
local f = methodPointer(monster[1], 'roar')
local g = methodPointer(monster[2], 'roar')
f()
g()
So I don't think we really need parameter-passing in the engine, only the ability to call anonymous zero-args functions. Perhaps some of the event data could be passed to the event callback, instead of held globally though.