You are not logged in.

Dear visitor, welcome to Runes of Magic EU. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

21

Friday, July 31st 2009, 2:34pm

Quoted from "HappyHorror;881283"

thx for GetTime() :woot:

i did like this
[...]and it doesn't depend on framerate :D

wrong.

OnUpdate is triggered on EVERY FRAME! so it is depending on the framerate xD

so it doesnt matter if you do it with GetTime() or with the predefined elapsedTime, which is the time between 2 OnUpdate() calls, both are dependent on <OnUpdate>, and both are called on each frame.

the mega huge advantage of the elapsedTime - way is:
performance!!!

GetTime() takes way more ressources than a normal subtraction of two floating point numbers, and that on every single Frame...

I played with up to 40-90fps depending on the zone,location,group... that would be 40-90 GetTime()calls per second compared to 40-90 subtractions... :-)

just do it like this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local timers = {};

HelloWorld = {
    countDown = function(self,elapsedTime)
        for index,timer in ipairs(timers)do
            timer.remainingTime = timer.remainingTime - elapsedTime;
            if(timer.remainingTime <= 0)then
                timer.func(timer.table,timer.values);
                self:removeTimer(index);
            end;
        end;
    end;
    
    addTimer = function(self,countDownValue,callBackTable,callBackFunction,callBackValues)
        local timer = {};
        local num;
        timer.remainingTime = countDownValue;
        timer.table = callBackTable;
        timer.func = callBackFunction;
        timer.values = callBackValues;
        num = #timers+1;
        timers[num] = timer;
        return num; --index of the Timer for later reuse(remove, change, whatever)
    end;
    
    removeTimer = function(self,num)
        if(!timers[num])then
            return false; --timer doesnt exist (anymore)
        end;
        return timers[num] = nil;
    end;
    
    changeTimer = function(self,num,countDownValue,callBackTable,callBackFunction,callBackValues)
        if(!timers[num])then --timers doesnt exist
            return false;
        end;
        timers[num].remainingTime = countDownValue or timers[num].remainingTime;    --change value if its != nil/0
        timers[num].table = callBackTable or timers[num].table;    --change value if its != nil/0
        timers[num].func = callBackFunction or timers[num].func;    --change value if its != nil/0
        timers[num].values = callBackvalues or timers[num].values;    --change value if its != nil/0
        return true;        
    end;
}
and the xml part:

Source code

1
2
3
4
5
[...]
<OnUpdate>
    HelloWorld:countDown(elapsedTime);
</OnUpdate>
[...]
now you have a small "Timer-Management" build-in :-)

you can add , change and remove Timers like you want to.


@HappyHorror - Slashcommands
its no "event"... take a look at some addons using slashcommands, you have to register your commands together with a callBackFunction which is called then
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

22

Friday, July 31st 2009, 3:32pm

@HappyHorror please read only Sl4ker messages, not mine, I made too much mistakes

@sl4ker
Doh ... performance, performance ... trying to put this in my little head wtf I never realize that OnUpdate was trigger on every frame rate, in fact, I never think about it. Blame on me.

Personaly I change my code to meet your advise and it give me (I use never ending timers)

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function SnowTools.update(frame, elapsedTime)
    if (SnowTools.ready) then
        
        SnowTools.ready = false

        for name, timer in pairs(SnowTools.timers) do
            if (not timer.paused) then
                timer.remainingTime = timer.remainingTime - elapsedTime
                if (timer.remainingTime <= 0) then
                    local success, errormsg = pcall(timer.func, SnowTools.UnpackArgs(timer.args));
                    timer.remainingTime =  timer.delay;
                    if (not success) then
                        SnowTools.error(name  .. " " .. errormsg)
                    end
                end
            end
        end        
        
        SnowTools.ready = true
    end
end
See ... no more GetTime() in my code :)

Any comment/suggestion? Is the usage of pcall good or bad?
The best thing to know is to know where you can find it

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

23

Friday, July 31st 2009, 4:30pm

your parameter "frame" .. shouldnt it be "self" ?:P thats a huge difference :-)

and pcall().. never used it^^ dont know whether its good or not.

last time I developed sth in lua is aprox 5months ago :-)

only C and Java since then :-) so I forgot about a lot of LUA-specific functions
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

24

Friday, July 31st 2009, 5:02pm

Quoted from "Sl4ker;881948"

your parameter "frame" .. shouldnt it be "self" ?:P thats a huge difference :-)
frame is the XML itself, but we don't care cause I don't use it :)

Thanks a lot for your help, it is very appreciated
The best thing to know is to know where you can find it

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

25

Friday, July 31st 2009, 7:53pm

Quoted from "TigerSmile;882036"

frame is the XML itself, but we don't care cause I don't use it :)

Thanks a lot for your help, it is very appreciated

the difference which I meant was:

Source code

1
2
3
function SnowTools.update(frame, elapsedTime)
 [...]
end;


will have "SnowTools" as "frame" when called like this:
SnowTools:update(elapsedTime)

if you want to give an additional parameter called frame (the frame which called it e.g.) you should do it like this:

Source code

1
function SnowTools.update(self,frame, elapsedTime)

and call it in the xml:

Source code

1
SnowTools:update(this,elapsedTime);



just a little hint :P

gl with ur project
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

26

Friday, July 31st 2009, 8:03pm

Quoted from "Sl4ker;881679"

wrong.

OnUpdate is triggered on EVERY FRAME! so it is depending on the framerate xD

so it doesnt matter if you do it with GetTime() or with the predefined elapsedTime, which is the time between 2 OnUpdate() calls, both are dependent on <OnUpdate>, and both are called on each frame.

the mega huge advantage of the elapsedTime - way is:
performance!!!

GetTime() takes way more ressources than a normal subtraction of two floating point numbers, and that on every single Frame...

I played with up to 40-90fps depending on the zone,location,group... that would be 40-90 GetTime()calls per second compared to 40-90 subtractions... :-)

just do it like this:

Source code

1
...
and the xml part:

Source code

1
2
[...]
...
now you have a small "Timer-Management" build-in :-)

you can add , change and remove Timers like you want to.


@HappyHorror - Slashcommands
its no "event"... take a look at some addons using slashcommands, you have to register your commands together with a callBackFunction which is called then


i copied this code and got 2 error messages:

1) call HelloWorld_Frame's OnUpdate, line: [string '?']:3: attempt to index global 'HelloWorld' (a nil value)

2) interface\AddOns\1\HelloWorld.lua [string '?']:27: unexpected symbol near '!'

my files was

HelloWorld.toc

Source code

1
2
HelloWorld.lua
HelloWorld.xml


HelloWorld.xml

Source code

1
2
3
4
5
6
7
8
9
<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/UI.xsd">
    <Frame name="HelloWorld_Frame">
        <Scripts>
       <OnUpdate>
            HelloWorld:countDown(elapsedTime);
       </OnUpdate>
        </Scripts>
    </Frame>
</Ui>


HelloWorld.lua

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
local timers = {};

HelloWorld = {
    countDown = function(self,elapsedTime)
        for index,timer in ipairs(timers)do
            timer.remainingTime = timer.remainingTime - elapsedTime;
            if(timer.remainingTime <= 0)then
                timer.func(timer.table,timer.values);
                self:removeTimer(index);
            end;
        end;
    end;
    
    addTimer = function(self,countDownValue,callBackTable,callBackFunction,callBackValues)
        local timer = {};
        local num;
        timer.remainingTime = countDownValue;
        timer.table = callBackTable;
        timer.func = callBackFunction;
        timer.values = callBackValues;
        num = #timers+1;
        timers[num] = timer;
        return num; --index of the Timer for later reuse(remove, change, whatever)
    end;
    
    removeTimer = function(self,num)
        if(!timers[num])then
            return false; --timer doesnt exist (anymore)
        end;
        return timers[num] = nil;
    end;
    
    changeTimer = function(self,num,countDownValue,callBackTable,callBackFunction,callBackValues)
        if(!timers[num])then --timers doesnt exist
            return false;
        end;
        timers[num].remainingTime = countDownValue or timers[num].remainingTime;    --change value if its != nil/0
        timers[num].table = callBackTable or timers[num].table;    --change value if its != nil/0
        timers[num].func = callBackFunction or timers[num].func;    --change value if its != nil/0
        timers[num].values = callBackvalues or timers[num].values;    --change value if its != nil/0
        return true;        
    end;
}

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

27

Friday, July 31st 2009, 8:21pm

oh yeah, 2 small errors:P

heres the final code:
(too used to C...)

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local timers = {};

local HelloWorld = {
    countDown = function(self,elapsedTime)
        for index,timer in ipairs(timers)do
            timer.remainingTime = timer.remainingTime - elapsedTime;
            if(timer.remainingTime <= 0)then
                timer.func(timer.table,timer.values);
                self:removeTimer(index);
            end;
        end;
    end;
    
    addTimer = function(self,countDownValue,callBackTable,callBackFunction,callBackValues)
        local timer = {};
        local num;
        timer.remainingTime = countDownValue;
        timer.table = callBackTable;
        timer.func = callBackFunction;
        timer.values = callBackValues;
        num = #timers+1;
        timers[num] = timer;
        return num; --index of the Timer for later reuse(remove, change, whatever)
    end;
    
    removeTimer = function(self,num)
        if( not timers[num])then
            return false; --timer doesnt exist (anymore)
        end;
        return timers[num] = nil;
    end;
    
    changeTimer = function(self,num,countDownValue,callBackTable,callBackFunction,callBackValues)
        if( not timers[num])then --timers doesnt exist
            return false;
        end;
        timers[num].remainingTime = countDownValue or timers[num].remainingTime;    --change value if its != nil/0
        timers[num].table = callBackTable or timers[num].table;    --change value if its != nil/0
        timers[num].func = callBackFunction or timers[num].func;    --change value if its != nil/0
        timers[num].values = callBackvalues or timers[num].values;    --change value if its != nil/0
        return true;        
    end;
}

_G.HelloWorld = HelloWorld;
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

28

Friday, July 31st 2009, 9:16pm

Quoted from "Sl4ker;882433"

oh yeah, 2 small errors:P

heres the final code:
(too used to C...)

Source code

1
...


thx, was a little error, but i solved it by changing

Source code

1
2
3
...
    return timers[num] = nil;
...
on

Source code

1
2
3
4
...
    timers[num] = nil;
        return timers[num];
...
now can you explaing how use this "Timer-Management"? :D

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

29

Friday, July 31st 2009, 9:45pm

Quoted from "HappyHorror;882511"

thx, was a little error, but i solved it by changing

Source code

1
2
3
...
    return timers[num] = nil;
...
on

Source code

1
2
3
4
...
    timers[num] = nil;
        return timers[num];
...
now can you explaing how use this "Timer-Management"? :D

oh I see another error xD

this line should be:

Source code

1
return [B]not ([/B]timers[num] = nil[B])[/B];

it should return true ;P

and now the explanation:

you can add Timers with myNewTimerNumber = HelloWorld:addTimer(...), just use the right arguments :-)

after countDownValue seconds, the given function callBackFunction is called, and all required arguments are given to it.

the meaning of callBackTable is, that inside the callBackFunction you can use "self" for every table you want to (callBackTable).

callBackValues should be a table or nil.

if you need more explanations, just ask :-)
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

30

Saturday, August 1st 2009, 2:21pm

Quoted from "Sl4ker;882546"



Source code

1
return [B]not ([/B]timers[num] = nil[B])[/B];
it should return true ;P

...

if you need more explanations, just ask :-)


this line also generate an error

Source code

1
interface\addOns\1\HelloWorld.lua [string '?']:30: ')' expected near '='


i think lua can't return value of expression... it can return only value

what is "callBackTable" for?

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

31

Saturday, August 1st 2009, 4:31pm

Quoted from "HappyHorror;883413"

this line also generate an error

Source code

1
interface\addOns\1\HelloWorld.lua [string '?']:30: ')' expected near '='
i think lua can't return value of expression... it can return only value

ok, long time not written anything in LUA :P

Source code

1
2
timers[num] = nil;
return true;

Quoted


what is "callBackTable" for?
just read this to understand it :-)
http://www.lua.org/pil/16.html

not giving the callBackTable would result in the local "timer" being the "calling" table of the function... and this can really suck if you dont pay attention to it :P
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

32

Saturday, August 1st 2009, 5:05pm

thx, trying... but i still don't understand, what parameter will be correct for "callBackTable" when i calling "AddTimer" function?

also tell me please - how set "callBackFunction" correct? like

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
In xml part

...
      HelloWorld:addTimer(5,nil,SayHello,nil) -- is this correct, if
...

In lua part

HelloWorld = {

...

    SayHello = function(self)
          DEFAULT_CHAT_FRAME:AddMessage("Hello!");
    end;
}

...



1 more question:

do you know any good xml manuals? i found some, but they crap...

i still don't know what parameters can be used for objects in xml files and what tags objects can use

like <frame> has parameter "parent", "inherits"... tags <size>, <anchors>...

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

33

Saturday, August 1st 2009, 7:11pm

callBackTable is needed for the function you give to "HelloWorld:addTimer"... so if you have a function:

Source code

1
2
3
4
5
6
7
8
9
10
11
HelloWorld.Security.sessionExpired(self)
     self:logout;                      -- self refers to HelloWorld.Security Table!
     self.whatever = false;
end;

or

HelloWorld.Security:sessionExpired()
     self:logout;                     -- self refers to HelloWorld.Security Table!
     self.whatever = false;
end;
and you set a timer with this function:

Source code

1
2
3
HelloWorld.Security.login = function(self,username,password)
      ...
end;
you would give the following parameters (assuming the session expires after 10minutes)

Source code

1
2
[...]
     HelloWorld:addTimer(600,self,sessionExpired,nil); -- self refers to HelloWorld.Security !!
if the countDown is over, the function sessionExpired will be called, and "HelloWorld.Security" will be the "Operating" table, in which the function is located then...(otherwise the operating table would be "timer" in the for - statement!)
if you wont pass "HelloWorld.Security" in as argument, you would have to declare the "self" inside every function you pass to the timer-framework :-)
and its really easy to make mistakes there ...


to the xml issues:

just open the ui.xsd scheme file in the interface.fdb/wordxml ... theres everything you need to know.

for more generell information on xml and scheme files, you will have to visit the appropriate sites.
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

34

Saturday, August 1st 2009, 7:32pm

what mean symbol # in line

Source code

1
2
3
...
num = [B]#[/B]timers+1;
...
hm... i tryed test timer, but there is error

Source code

1
call HelloWorld_Frame's OnUpdate, line: [string '?']:8: attempt to call field 'func' (a nil value)
my files was

HelloWorld.toc

Source code

1
2
HelloWorld.lua
HelloWorld.xml
HelloWorld.xml (to add new timer just press button in frame called "New timer")

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/UI.xsd">
    <Frame name="HelloWorld_Frame" inherits="UICommonFrameTemplate" enableMouse="true" hidden="false" parent="UIParent">
    <Size>
            <AbsDimension x="200" y="200" />
        </Size>
        <Anchors>
        <Anchor point="CENTER">
            <Offset>
                <AbsDimension x="0" y="0"/>
            </Offset>
        </Anchor>
        </Anchors>
    <Scripts>
       <OnUpdate>
            HelloWorld:countDown(elapsedTime);
       </OnUpdate>
           <OnMouseDown>
                this:StartMoving("CENTER");
           </OnMouseDown>
           <OnMouseUp>
                this:StopMovingOrSizing();
           </OnMouseUp>
           <OnEscapePressed>
                this:Hide();
           </OnEscapePressed>
        </Scripts>
    <Frames>    
        <Button name="MyButton" inherits="UIPanelButtonTemplate" text="New timer">
            <Size>
                <AbsDimension x="80" y="26"/>
            </Size>
            <Anchors>
                <Anchor point="CENTER">
            <Offset>
                <AbsDimension x="0" y="0"/>
            </Offset>
                </Anchor>
            </Anchors>
            <Scripts>
                <OnClick>
            HelloWorld:addTimer(5,self,SayHello,nil);
        </OnClick>
            </Scripts>
        </Button>
    </Frames>
    </Frame>
</Ui>
HelloWorld.lua

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local timers = {};

HelloWorld = {
    countDown = function(self,elapsedTime)
        for index,timer in ipairs(timers)do
            timer.remainingTime = timer.remainingTime - elapsedTime;
            if(timer.remainingTime <= 0)then
                timer.func(timer.table,timer.values);
                self:removeTimer(index);
            end;
        end;
    end;
    
    addTimer = function(self,countDownValue,callBackTable,callBackFunction,callBackValues)
        local timer = {};
        local num;
        timer.remainingTime = countDownValue;
        timer.table = callBackTable;
        timer.func = callBackFunction;
        timer.values = callBackValues;
        num = #timers+1;
        timers[num] = timer;
        return num; --index of the Timer for later reuse(remove, change, whatever)
    end;
    
    removeTimer = function(self,num)
        if( not timers[num])then
            return false; --timer doesnt exist (anymore)
        end;
    timers[num] = nil;
    return true;
    end;
    
    changeTimer = function(self,num,countDownValue,callBackTable,callBackFunction,callBackValues)
        if( not timers[num])then --timers doesnt exist
            return false;
        end;
        timers[num].remainingTime = countDownValue or timers[num].remainingTime;    --change value if its != nil/0
        timers[num].table = callBackTable or timers[num].table;    --change value if its != nil/0
        timers[num].func = callBackFunction or timers[num].func;    --change value if its != nil/0
        timers[num].values = callBackvalues or timers[num].values;    --change value if its != nil/0
        return true;        
    end;
}

[B]    function HelloWorld:SayHello()--only added my func here
    DEFAULT_CHAT_FRAME:AddMessage("Hello!");
    end;[/B]

_G.HelloWorld = HelloWorld

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

35

Saturday, August 1st 2009, 8:41pm

Quoted from "HappyHorror;883830"

what mean symbol # in line

Source code

1
2
3
...
num = [B]#[/B]timers+1;
...

the symbol # means the highest index in an array (the indexed table is an array here).. so num holds the maximum index + 1 (the next index, at which the new timer will be placed)

Quoted


hm... i tryed test timer, but there is error

Source code

1
call HelloWorld_Frame's OnUpdate, line: [string '?']:8: attempt to call field 'func' (a nil value)
my files was

HelloWorld.toc

Source code

1
2
HelloWorld.lua
HelloWorld.xml
HelloWorld.xml (to add new timer just press button in frame called "New timer")

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/UI.xsd">
    <Frame name="HelloWorld_Frame" inherits="UICommonFrameTemplate" enableMouse="true" hidden="false" parent="UIParent">
    <Size>
            <AbsDimension x="200" y="200" />
        </Size>
        <Anchors>
        <Anchor point="CENTER">
            <Offset>
                <AbsDimension x="0" y="0"/>
            </Offset>
        </Anchor>
        </Anchors>
    <Scripts>
       <OnUpdate>
            HelloWorld:countDown(elapsedTime);
       </OnUpdate>
           <OnMouseDown>
                this:StartMoving("CENTER");
           </OnMouseDown>
           <OnMouseUp>
                this:StopMovingOrSizing();
           </OnMouseUp>
           <OnEscapePressed>
                this:Hide();
           </OnEscapePressed>
        </Scripts>
    <Frames>    
        <Button name="MyButton" inherits="UIPanelButtonTemplate" text="New timer">
            <Size>
                <AbsDimension x="80" y="26"/>
            </Size>
            <Anchors>
                <Anchor point="CENTER">
            <Offset>
                <AbsDimension x="0" y="0"/>
            </Offset>
                </Anchor>
            </Anchors>
            <Scripts>
                <OnClick>
            HelloWorld:addTimer(5,self,SayHello,nil);
        </OnClick>
            </Scripts>
        </Button>
    </Frames>
    </Frame>
</Ui>
HelloWorld.lua

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local timers = {};

HelloWorld = {
    countDown = function(self,elapsedTime)
        for index,timer in ipairs(timers)do
            timer.remainingTime = timer.remainingTime - elapsedTime;
            if(timer.remainingTime <= 0)then
                timer.func(timer.table,timer.values);
                self:removeTimer(index);
            end;
        end;
    end;
    
    addTimer = function(self,countDownValue,callBackTable,callBackFunction,callBackValues)
        local timer = {};
        local num;
        timer.remainingTime = countDownValue;
        timer.table = callBackTable;
        timer.func = callBackFunction;
        timer.values = callBackValues;
        num = #timers+1;
        timers[num] = timer;
        return num; --index of the Timer for later reuse(remove, change, whatever)
    end;
    
    removeTimer = function(self,num)
        if( not timers[num])then
            return false; --timer doesnt exist (anymore)
        end;
    timers[num] = nil;
    return true;
    end;
    
    changeTimer = function(self,num,countDownValue,callBackTable,callBackFunction,callBackValues)
        if( not timers[num])then --timers doesnt exist
            return false;
        end;
        timers[num].remainingTime = countDownValue or timers[num].remainingTime;    --change value if its != nil/0
        timers[num].table = callBackTable or timers[num].table;    --change value if its != nil/0
        timers[num].func = callBackFunction or timers[num].func;    --change value if its != nil/0
        timers[num].values = callBackvalues or timers[num].values;    --change value if its != nil/0
        return true;        
    end;
}

[B]    function HelloWorld:SayHello()--only added my func here
    DEFAULT_CHAT_FRAME:AddMessage("Hello!");
    end;[/B]

_G.HelloWorld = HelloWorld
ähm yes... you have to type it like this in your xml file:

Source code

1
HelloWorld:addTimer(5,HelloWorld,HelloWorld.sayHello,nil);
then it should work ;-)

the function you give to addTimer() has to hold the complete path relative to your current scope, and the callBackTable holds the operating and enclosing table of this function.
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

36

Saturday, August 1st 2009, 9:06pm

thx, now it work :weekendfeeling:


Quoted from "Sl4ker;883803"

callBackTable is needed for the function you give to "HelloWorld:addTimer"... so if you have a function:

Source code

1
2
3
4
5
6
7
8
9
10
11
HelloWorld.Security.sessionExpired(self)
     self:logout;                      -- self refers to HelloWorld.Security Table!
     self.whatever = false;
end;

or

HelloWorld.Security:sessionExpired()
     self:logout;                     -- self refers to HelloWorld.Security Table!
     self.whatever = false;
end;
and you set a timer with this function:

Source code

1
2
3
HelloWorld.Security.login = function(self,username,password)
      ...
end;
you would give the following parameters (assuming the session expires after 10minutes)

Source code

1
2
[...]
     HelloWorld:addTimer(600,self,sessionExpired,nil); -- self refers to HelloWorld.Security !!
if the countDown is over, the function sessionExpired will be called, and "HelloWorld.Security" will be the "Operating" table, in which the function is located then...(otherwise the operating table would be "timer" in the for - statement!)
if you wont pass "HelloWorld.Security" in as argument, you would have to declare the "self" inside every function you pass to the timer-framework :-)
and its really easy to make mistakes there ...


...


what difference beetwen symbols . and : before SessionExpired ?

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

37

Saturday, August 1st 2009, 9:33pm

Quoted from "HappyHorror;883934"

thx, now it work :weekendfeeling:

np :-)

Quoted


what difference beetwen symbols . and : before SessionExpired ?

the link I posted earlier descripes this very well :P

heres a short quote from the page:

Quoted from "http://www.lua.org/pil/16.html"


A more flexible approach is to operate on the receiver of the operation. For that, we would have to define our method with an extra parameter, which tells the method on which object it has to operate. This parameter usually has the name self or this:
function Account.withdraw (self, v)
self.balance = self.balance - v
end
Now, when we call the method we have to specify on which object it has to operate: a1 = Account; Account = nil
...
a1.withdraw(a1, 100.00) -- OK
With the use of a self parameter, we can use the same method for many objects: a2 = {balance=0, withdraw = Account.withdraw}
...
a2.withdraw(a2, 260.00)
This use of a self parameter is a central point in any object-oriented language. Most OO languages have this mechanism partly hidden from the programmer, so that she does not have to declare this parameter (although she still can use the name self or this inside a method). Lua can also hide this parameter, using the colon operator. We can rewrite the previous method definition as
function Account:withdraw (v)
self.balance = self.balance - v
end
and the method call as a:withdraw(100.00)
The effect of the colon is to add an extra hidden parameter in a method definition and to add an extra argument in a method call. The colon is only a syntactic facility, although a convenient one; there is nothing really new here. We can define a function with the dot syntax and call it with the colon syntax, or vice-versa, as long as we handle the extra parameter correctly: Account = { balance=0,
withdraw = function (self, v)
self.balance = self.balance - v
end
}

function Account:deposit (v)
self.balance = self.balance + v
end

Account.deposit(Account, 200.00)

Account:withdraw(100.00)
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

38

Monday, August 3rd 2009, 10:03am

Quoted from "Sl4ker;882376"

the difference which I meant was:
...
just a little hint :P
gl with ur project


Once again, thanks and thanks, really appreciated. How can we find this kind of hint? I mean excepted in your brain, or can you rent it? ;)

P.S: Been a Java Developer I stoped using : (colon) (too much confusing for me) :(
The best thing to know is to know where you can find it

39

Monday, August 3rd 2009, 12:38pm

hm... i found a little problem with timer, if i add second timer when first is working, then second timer ignors

try this code, i only added frame with button (just click button twice to add 2 new timers) and messages in chat will show you some steps of work

HelloWorld.toc

Source code

1
2
HelloWorld.lua
HelloWorld.xml


HelloWorld.lua

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local timers = {};

HelloWorld = {
    countDown = function(self,elapsedTime)
        for index,timer in ipairs(timers)do
            timer.remainingTime = timer.remainingTime - elapsedTime;
            if(timer.remainingTime <= 0)then
                timer.func(timer.table,timer.values);
				DEFAULT_CHAT_FRAME:AddMessage("call remove timer");
                self:removeTimer(index);
            end;
        end;
    end;
    
    addTimer = function(self,countDownValue,callBackTable,callBackFunction,callBackValues)
        local timer = {};
        local num;
        timer.remainingTime = countDownValue;
        timer.table = callBackTable;
        timer.func = callBackFunction;
        timer.values = callBackValues;
        num = #timers+1;
	DEFAULT_CHAT_FRAME:AddMessage("timer &#8470; "..num.." created");
        timers[num] = timer;
        return num; --index of the Timer for later reuse(remove, change, whatever)
    end;
    
    removeTimer = function(self,num)
		DEFAULT_CHAT_FRAME:AddMessage("removing timer &#8470; "..num);
        if( not timers[num])then
			DEFAULT_CHAT_FRAME:AddMessage("timer doesnt exist");
            return false; --timer doesnt exist (anymore)
        end;
		DEFAULT_CHAT_FRAME:AddMessage("timer &#8470; "..num.. " was removed");
		timers[num] = nil;
	return true;
    end;
    
    changeTimer = function(self,num,countDownValue,callBackTable,callBackFunction,callBackValues)
        if( not timers[num])then --timers doesnt exist
            return false;
        end;
        timers[num].remainingTime = countDownValue or timers[num].remainingTime;    --change value if its != nil/0
        timers[num].table = callBackTable or timers[num].table;    --change value if its != nil/0
        timers[num].func = callBackFunction or timers[num].func;    --change value if its != nil/0
        timers[num].values = callBackvalues or timers[num].values;    --change value if its != nil/0
        return true;        
    end;
}

    function HelloWorld.SayHello()
		DEFAULT_CHAT_FRAME:AddMessage("Hello!");
    end;

_G.HelloWorld = HelloWorld;


HelloWorld.xml

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/UI.xsd">
    <Frame name="MyFrame" inherits="UICommonFrameTemplate" enableMouse="true" hidden="false" parent="UIParent">
	<Size>
        <AbsDimension x="200" y="200" />
    </Size>
    <Anchors>
		<Anchor point="CENTER">
            <Offset>
                <AbsDimension x="0" y="0"/>
            </Offset>
        </Anchor>
    </Anchors>
	<Scripts>
	    <OnMouseDown>
            this:StartMoving("CENTER");
        </OnMouseDown>
        <OnMouseUp>
            this:StopMovingOrSizing();
        </OnMouseUp>
		<OnEscapePressed>
            this:Hide();
        </OnEscapePressed>
    </Scripts>
	<Frames>
        <Button name="MyButton" inherits="UIPanelButtonTemplate" text="Start">
			<Size>
				<AbsDimension x="100" y="30"/>
			</Size>
			<Anchors>
				<Anchor point="CENTER">
					<Offset>
						<AbsDimension x="0" y="0"/>
					</Offset>
				</Anchor>
			</Anchors>
			<Scripts>
				<OnClick> 
					HelloWorld:addTimer(5,HelloWorld,HelloWorld.SayHello,nil);
				</OnClick>
			</Scripts>
        </Button>
    </Frames>
	</Frame>
	<Frame name="HelloWorld_Frame2" parent="UIParent">
	<Scripts>
		<OnUpdate>
    		HelloWorld:countDown(elapsedTime);
		</OnUpdate>
	</Scripts>
    </Frame>
</Ui>

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

40

Monday, August 3rd 2009, 1:52pm

try to change

Source code

1
2
3
    function HelloWorld.SayHello()
        DEFAULT_CHAT_FRAME:AddMessage("Hello!");
    end;
to

Source code

1
2
3
function HelloWorld.SayHello(self)
[...]
end;
if it still doesnt work, try to change the addTimer to the following:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    addTimer = function(self,countDownValue,callBackTable,callBackFunction,callBackValues)
        local timer = {};
        local num;
        timer.remainingTime = countDownValue;
        timer.table = callBackTable;
        timer.func = callBackFunction;
        timer.values = callBackValues;
        for index,_ in ipairs(timers)do
            num = index or num++;
            if(index == nil)then
                  timers[num] = timer;
                  break;
            end;
        end;
    DEFAULT_CHAT_FRAME:AddMessage("timer &#8470; "..num.." created");
        return num; --index of the Timer for later reuse(remove, change, whatever)
    end;
cant test it, cause I didnt update rom for the last 4-5Months :P
but I guess it should work now... if not, try to debug it with a self written print() function to print the values of timers before and after creation/deletion of new ones
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P