View Single Post
05-27-11, 03:18 PM   #10
Myke916
A Deviate Faerie Dragon
 
Myke916's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 18
ok... well wiki has an example

here is the wiki example: javascript not lua

Code:
function Queue(){
    this.data = [];
    this.head = 0;
    this.size = 0;
 
    this.size = function(){
        return this.size < 0 ? 0 : this.size;
    }
 
    this.queue = function(obj){
        this.data[this.size++] = obj;
    }
 
    this.dequeue = function(){
        //Amortices the shrink frequency of the queue
        if(--this.size < this.data.length*0.9){
            this.data = this.data.slice(this.head);
            this.head = 0;
        }
        return this.data[this.head++];
    }
 
    this.peek = function(){
        return this.data[this.head];
    }
 
    this.isEmpety = function(){
        return this.size <= 0;
    }
}
so how do i format this in Lua? the code is a little different...

seccond.. well... if i had a lua example of this code i could figure out what is next, i would assume sharing the queue on the addon channel to process information...

i believe that would be in the dequeue or isempty function...

Basically this is supposed to tell me when a user is online, and if they are in the queue... if they are not in the queue AddQueue() then loop the normal function of scanning for users online with the addon running... if the user goes offline, remove them from the queue...

but like i said this is java, i have made 3 attempts to build this in lua, and failed the first time, the seccond time was 30% working but had a few minor errors... mostly script wise....

BUT the main importance is that this queue needs to be in constant communications with others using this addon, so its not a local script... its shared between users... and thus, it cannot read local variables must read shared variables... (where i got lost on the 2nd attempt..)

thus comes the part where the active queue user ... say for example:

Client1 = 0
Client3 = 1
Client2 = 2
Client4 = 3

Client 0 send the kill command addon_name:UnregisterEvent("THISEVENT") to client 3,2,4 - but! Client 3,2,4 continue to check the queue if client1 is online like this:

Code:
if UnitIsConnected(Client1) == 1 then
--do nothing - continue waiting for offline
elseif UnitIsConnected(Client1) == 0 then
addon_name:RegisterEvent("THISEVENT")
but it has to be brodcast on the addon channel so we use this:
Code:
    SendAddonMessage("ADDONNAME", QUEUESTATUS, "GUILD", "SENDER")
of coarse the event has to be properly registered, and it is said specifically that the "SENDER" can be omited and is only used when communicating on the WHISPER channel, but i found that it can be helpful in identifying other users who send data on a larger number basis on the guild channel... (re-inventing the wheel?!)

IVE WRITTEN THIS CODE 3 TIMES, i need some help please.. i fail'd... i wasted 3 days... and countless hours yelling at my laptop... and it kept yelling back...
  Reply With Quote