WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Need help with lua error (https://www.wowinterface.com/forums/showthread.php?t=5536)

thejoester 07-21-06 02:06 AM

Need help with lua error
 
Anyone know about coroutines in Lua?

Here is the setup. I am working on an Addon to capture a screenshot when you level up. I got that part working however, the screenshot does not show the golden sparks. So I need to delay the screenshot for a second or two.

I tried the following code to delay the screenshot:

Code:

  local sstime;
  sstime = time();
  sstime = (sstime + x);               
  repeat
                                                       
  until sstime < time()                               
  Screenshot();

The result of this was the game would "freeze" for however many seconds you set (x) and then take the screenshot at the same point.

So I read up and I am trying to use coroutines as a way to "thread" the timer. I have the following code in my Lua:

Code:

local cr = coroutine.create(function(x)       
                local sstime;
                sstime = time();
                sstime = (sstime + x);               
                repeat
                                                       
                until sstime < time()                               
                Screenshot();

       
                coroutine.yield(x);
        end
end)

function dingrecorder_Onevent(event)
        DEFAULT_CHAT_FRAME:AddMessage("/g Ding " .. arg1);
       

        if (event == "PLAYER_LEVEL_UP") then

                if (arg1 ~= nil) then
                        coroutine.resume(cr,2);
                end
        end

       
end

and upon start I get the error:

Quote:

Interface\Addons\DingRecorder\Dingrecorder.lua:1: attempt to index global 'coroutine' (a nil value)
any ideas?

thanks in advance!

Nyrine 07-21-06 11:09 AM

The WoW implementation of lua seems to have lots of things missing, is the coroutine functionality one of those ?

Iriel 07-21-06 03:12 PM

Quote:

Originally Posted by Nyrine
The WoW implementation of lua seems to have lots of things missing, is the coroutine functionality one of those ?

Yes, coroutines are missing.

You may just want to look at a timer library like Timex or Chronos, or roll your own using an OnUpdate handler.


All times are GMT -6. The time now is 08:37 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI