Thread Tools Display Modes
Prev Previous Post   Next Post Next
07-21-06, 02:06 AM   #1
thejoester
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jun 2006
Posts: 10
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:

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

thanks in advance!
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Need help with lua error


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off