I've got some code similar to this in my game for different types of entities.
knight.sm=cocreate( function () while(knight.alive) do w=knight.w h=knight.h s=knight.s if btn(0) then ... ... .. ..
Basically inside the function I'm creating a coroutine from I just use the "knight" reference from global scope as a "this" reference, so to speak. But...now I want to create a different type of entity within a loop, using a similar approach to the above.
for m=1,10 do ::redo:: .... chest.sm=cocreate( function() while chest.alive==true do
The problem I'm running into is that that "chest" variable inside the loop, only ever seems to refer to one chest (presumably the very first time the function() is processed by lua).
I want to create a coroutine for each chest entity, which has a reference to "that" chest for each one in the loop. I'm sure there's a way to do something like that but I'm fairly new to lua.
[Please log in to post a comment]