Log In  

I've got some code similar to this in my game for different types of entities.

 function ()
  while(knight.alive) do

   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::

    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.

P#40244 2017-05-06 16:43 ( Edited 2017-05-06 20:46)

Whoa nevermind, I just figured it out. I need to precede that chest variable with "local" when I first create it. That seemed to do the trick.

P#40245 2017-05-06 16:46 ( Edited 2017-05-06 20:46)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-11-21 20:12 | 0.010s | 2097k | Q:14