Quantcast
Need help with lua error - WoWInterface
Thread Tools Display Modes
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
07-21-06, 11:09 AM   #2
Nyrine
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 23
The WoW implementation of lua seems to have lots of things missing, is the coroutine functionality one of those ?
  Reply With Quote
07-21-06, 03:12 PM   #3
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
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.
  Reply With Quote

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

Thread Tools
Display Modes

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