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.

1

Wednesday, July 29th 2009, 10:47am

(events and timer) please explaing simple error in addon-example

i made addon with event like here http://www.theromwiki.com/index.php/Addon_Tutorial

but when game loads i occure an error: interface\AddOns\HelloWorld\HelloWorld.lua [string '?']:11: attempt to index local 'frame' (a nil value)

why it happens and how resolve it?

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

2

Wednesday, July 29th 2009, 12:04pm

we need the complete code you have...

but I suggest you have forgotten to give (this) as parameter to your function.
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

3

Wednesday, July 29th 2009, 12:40pm

HelloWorld.lua

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local HelloWorld = {} -- the addon namespace, all your functions should be placed inside here instead of as globals.
_G.HelloWorld = HelloWorld -- expose it to the global scope
local frame = _G.HelloWorld_Frame -- made in the XML

--- Print out "Hello, World!" to the chat frame
-- @usage HelloWorld:Print()
function HelloWorld:Print()
    DEFAULT_CHAT_FRAME:AddMessage("Hello, World!")
end

frame:RegisterEvent("VARIABLES_LOADED")

function HelloWorld:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
    -- this is a fun trick that will call a method named the event, passing in all the relevant args.
    self[event](self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function HelloWorld:VARIABLES_LOADED()
    self:Print()
end



HelloWorld.toc

Source code

1
2
3
4
5
6
7
## Title: 1
## Version: 0.1
## Notes: 2
## Author: 3

HelloWorld.lua
HelloWorld.xml

HelloWorld.xml

Source code

1
2
3
4
5
6
7
8
9
10
<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>
            <OnEvent>
                -- call the OnEvent method on our addon, passing in any relevant args.
                HelloWorld:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
            </OnEvent>
        </Scripts>
    </Frame>
</Ui>

4

Wednesday, July 29th 2009, 2:22pm

i did some tests with RegisterEvent direct from xml:

deleted lines in HelloWorld.lua

Source code

1
2
3
local frame = _G.HelloWorld_Frame -- made in the XML

frame:RegisterEvent("VARIABLES_LOADED");


and added to the HelloWorld.xml

Source code

1
2
3
<OnLoad>
this:RegisterEvent("VARIABLES_LOADED");
</OnLoad>


and all work fine, but i still have a question:

why doesn't work code

Source code

1
2
3
local frame = _G.HelloWorld_Frame -- made in the XML

frame:RegisterEvent("VARIABLES_LOADED");

5

Wednesday, July 29th 2009, 3:13pm

Hi, I am not sure about that but in your .toc file you write:

HelloWorld.lua
HelloWorld.xml

So when the lua will be loaded, it doesn't know the xml because it will be load after the lua, so "local frame = _G.HelloWorld_Frame will be null

Try to put the HelloWorld.xml before the HelloWorld.lua in your .toc file

6

Wednesday, July 29th 2009, 3:24pm

Quoted from "TigerSmile;876756"

Hi, I am not sure about that but in your .toc file you write:

HelloWorld.lua
HelloWorld.xml

So when the lua will be loaded, it doesn't know the xml because it will be load after the lua, so "local frame = _G.HelloWorld_Frame will be null

Try to put the HelloWorld.xml before the HelloWorld.lua in your .toc file


replaced - and it work :) thx.


but got new errors with next example - timer :(

in HelloWorld.toc

Source code

1
2
3
4
5
6
7
## Title: 1
## Version: 0.1
## Notes: 2
## Author: 3

HelloWorld.xml
HelloWorld.lua


in 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
local HelloWorld = {} -- the addon namespace, all your functions should be placed inside here instead of as globals.
_G.HelloWorld = HelloWorld -- expose it to the global scope
local frame = _G.HelloWorld_Frame -- made in the XML

--- Print out "Hello, World!" to the chat frame
-- @usage HelloWorld:Print()
function HelloWorld:Print()
    DEFAULT_CHAT_FRAME:AddMessage("Hello, World!")
end

frame:RegisterEvent("VARIABLES_LOADED")

function HelloWorld:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
    -- this is a fun trick that will call a method named the event, passing in all the relevant args.
    self[event](self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function HelloWorld:VARIABLES_LOADED()
    self:Print()
end

local time_remaining = 5 -- in seconds
function HelloWorld:OnUpdate(elapsed)
    -- elapsed is the amount of time in seconds since the last frame tick
    
    time_remaining = time_remaining - elapsed
    if time_remaining > 0 then
        -- cut out early, we're not ready yet
        return
    end
    time_remaining = 5 -- reset to 5 seconds
    self:Print()
end


in HelloWorld.xml

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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>
            <OnEvent>
                -- call the OnEvent method on our addon, passing in any relevant args.
                HelloWorld:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
            </OnEvent>
            
            <OnUpdate>
                -- call the OnUpdate method on our addon
                HelloWorld:OnUpdate(arg1)
            </OnUpdate>
        </Scripts>
    </Frame>
</Ui>


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

error 2) call HelloWorld_Frame's OnUpdate, line: [string '?']:26: attempt to perform arithmetic on local 'elapsed' (a string value)

7

Thursday, July 30th 2009, 10:06am

the problem was solved - for correct work example with timer files should be:

HelloWorld.xml

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<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>
        <OnLoad>
        this:RegisterEvent("VARIABLES_LOADED");
        </OnLoad>
            <OnEvent>
                -- call the OnEvent method on our addon, passing in any relevant args.
                HelloWorld:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
            </OnEvent>
            
            <OnUpdate>
                -- call the OnUpdate method on our addon
                HelloWorld:OnUpdate(0.01)
            </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
local HelloWorld = {} -- the addon namespace, all your functions should be placed inside here instead of as globals.
_G.HelloWorld = HelloWorld -- expose it to the global scope
--local frame = _G.HelloWorld_Frame -- made in the XML

--- Print out "Hello, World!" to the chat frame
-- @usage HelloWorld:Print()
function HelloWorld:Print()
    DEFAULT_CHAT_FRAME:AddMessage("Hello, World!")
end

function HelloWorld:OnEvent(event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
    -- this is a fun trick that will call a method named the event, passing in all the relevant args.
    self[event](self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
end

function HelloWorld:VARIABLES_LOADED()
    self:Print()
end

local time_remaining = 5 -- in seconds
function HelloWorld:OnUpdate(elapsed)
    -- elapsed is the amount of time in seconds since the last frame tick
    
    time_remaining = time_remaining - elapsed
    if time_remaining > 0 then
        -- cut out early, we're not ready yet
        return
    end
    time_remaining = 5 -- reset to 5 seconds
    self:Print()
end
HelloWorld.toc order of lines

Source code

1
2
HelloWorld.lua
HelloWorld.xml

8

Thursday, July 30th 2009, 11:14am

the client ui doesn't update every 0.1 seconds unless it runs at a steady 10fps so it should be HelloWorld:OnUpdate(elapsedTime) or (this, elapsedTime) if you want the frame itself passed for whatever reason. that way you can set a timer for 10 seconds and it will fire after approximately 10 seconds regardless of the client's framerate. if you pass it 0.1 (10hz) when the client is running at say 100hz (0.01) then that 10 second timer will fire in 1 second.


Remember: when in doubt, look at someone else's plugin.
-Paeg

9

Thursday, July 30th 2009, 11:51am

Personaly, I think that this tutorial is not so good. First of all, it doesn't work which is very very bad for new addOn creator. How can you understand your mistake if the sample you got is not working :confused:

Second, it must be keep as simple as possible

Source code

1
2
-- this is a fun trick that will call a method named the event, passing in all the relevant args.
self[event](self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
This is for sure a nice trick but useless and confused for new creator.:panic:

If someone, fluent in english, got time to think about it, it would be very nice. :woot:

10

Thursday, July 30th 2009, 12:47pm

Quoted from "Paegus;878690"

the client ui doesn't update every 0.1 seconds unless it runs at a steady 10fps so it should be HelloWorld:OnUpdate(elapsedTime) or (this, elapsedTime) if you want the frame itself passed for whatever reason. that way you can set a timer for 10 seconds and it will fire after approximately 10 seconds regardless of the client's framerate. if you pass it 0.1 (10hz) when the client is running at say 100hz (0.01) then that 10 second timer will fire in 1 second.


Remember: when in doubt, look at someone else's plugin.



can you make a simple timer example, that work and doesn't depend on framerate? :D

ofcouse i tryed look in other addons, but all addons have many code and it hard for me studing from them

11

Thursday, July 30th 2009, 3:46pm

please explaing, what's wrong in my addon with even:

in HelloWorld.xml

Source code

1
2
3
4
5
6
7
8
9
10
11
12
<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">
    <OnLoad>
        this:RegisterEvent("CHAT_MSG_SAY");
    </OnLoad>
    <OnEvent>
        if (event == "CHAT_MSG_SAY") then
            DEFAULT_CHAT_FRAME:AddMessage("triggered event");
        end;
    </OnEvent>
    </Frame>
</Ui>
in HelloWorld.toc

Source code

1
HelloWorld.xml
when i writing anything in chat i don't recive message "triggered event"... why?

12

Thursday, July 30th 2009, 3:59pm

I don't know yet but hopefully it doesn't works :)

Each time, you get a message in say channel, you send a new message in the same channel which will trigger the same event ... and goes on. :zomg:

The result will be a none ending loop :)
The best thing to know is to know where you can find it

13

Thursday, July 30th 2009, 5:02pm

Quoted from "TigerSmile;879887"

I don't know yet but hopefully it doesn't works :)

Each time, you get a message in say channel, you send a new message in the same channel which will trigger the same event ... and goes on. :zomg:

The result will be a none ending loop :)


even if i do like this

HelloWorld.lua

Source code

1
2
3
4
5
6
7
8
9
local HelloWorld = {}
_G.HelloWorld = HelloWorld


function HelloWorld.WriteMessage(_event)
    if (_event == "CHAT_MSG_SAY") then
        _G.HelloWorld_Frame:Hide();-- when appears any message in chat, frame will hide
    end;
end;
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
<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="UIPanelBackdropFrame" enableMouse="true" hidden="false" parent="UIParent">
    <OnLoad>
        this:RegisterEvent("CHAT_MSG_SAY");
    </OnLoad>
    <OnEvent>
        HelloWorld.WriteMessage(_event);--call function, that will hide this frame
    </OnEvent>
    --frame visual components
    <Size>
        <AbsDimension x="100" y="100" />
    </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="$parent_CloseButton" inherits="UIPanelCloseButtonTemplate">
            <Size>
                <AbsDimension x="26" y="26"/>
            </Size>
            <Anchors>
                <Anchor point="TOPRIGHT">
                    <Offset><AbsDimension x="1" y="0"/></Offset>
                </Anchor>
            </Anchors>
            <Scripts>
                <OnClick>HelloWorld_Frame:Hide();</OnClick>
            </Scripts>
        </Button>
    </Frames>
    </Frame>
</Ui>
HelloWorld.toc

Source code

1
2
3
4
5
6
7
## Title: 1
## Version: 0.1
## Notes: 2
## Author: 3

HelloWorld.xml
HelloWorld.lua


my addon ignore event... hell, why?

Sl4ker

Intermediate

Posts: 1,985

Occupation: Ex- RoM-Zocker

  • Send private message

14

Thursday, July 30th 2009, 5:13pm

because you used _event and not event :-)

you cant just rename them in the xml file... these are predefined names

Quoted from "TigerSmile;879887"

I don't know yet but hopefully it doesn't works :)

Each time, you get a message in say channel, you send a new message in the same channel which will trigger the same event ... and goes on. :zomg:

The result will be a none ending loop :)

it wont, because he doesnt add any message to the "say channel".. the output will only be visible for him
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

15

Thursday, July 30th 2009, 8:16pm

Quoted from "Sl4ker;880031"

because you used _event and not event :-)

you cant just rename them in the xml file... these are predefined names


it wont, because he doesnt add any message to the "say channel".. the output will only be visible for him


thxm you're right

but main problem was in other thing - i didn't know, that

<OnLoad></OnLoad> , <OnEvent></OnEvent> , <OnUpdate></OnUpdate>

must be inside

<Scripts></Scripts>

;)


i still don't know how make timer, that doesn't depend on framerate... any sample please?

16

Friday, July 31st 2009, 10:04am

My Bad, sorry for my previous post and thanks to Sl4ker to correct me.

To create a timer based on time and not frame rate, you will have to play with "time" :D using the function GetTime()

For example :

Source code

1
2
3
4
5
6
7
8
9
10
local delay = 0.5
local lastCall = 0   -- next time your function will be called

MyAddon:OnUpdate(elapseTime)   -- declared in your XML file
   local currentTime = GetTime()
   if (currentTime > lastCall) then
      <Your function here>
      lastCall = currentTime + delay 
   end
end
It should work.
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

17

Friday, July 31st 2009, 10:29am

timer just work fine with OnUpdate() with elapsedTime....

GetTime has the same problem as elapsedTime in your example.. its only triggered inside OnUpdate() :-)

so GetTime2()-GetTime1() = elapsedTime..
but elapsedTime needs less performance

the only advantage of Timer based on GetTime() is, when you KNOW that at e.g. 6:00h you want sth to happen.
[Temeraire] - [Ikarus] - [AddOn-FAQ]
My english is not the yellow from the egg :-P

18

Friday, July 31st 2009, 11:11am

I tried to help but I think I better to stop for a while :shhh: cause I made to much mistakes and don't want to give bad answers to good questions ;)

By the way, I am glad to be corrected by you Sl4ker, it is a honnor, and I love Irakus.
The best thing to know is to know where you can find it

19

Friday, July 31st 2009, 11:39am

Quoted from "TigerSmile;881118"

My Bad, sorry for my previous post and thanks to Sl4ker to correct me.

To create a timer based on time and not frame rate, you will have to play with "time" :D using the function GetTime()

For example :

Source code

1
2
3
4
5
6
7
8
9
10
local delay = 0.5
local lastCall = 0   -- next time your function will be called

MyAddon:OnUpdate(elapseTime)   -- declared in your XML file
   local currentTime = GetTime()
   if (currentTime > lastCall) then
      <Your function here>
      lastCall = currentTime + delay 
   end
end
It should work.


thx for GetTime() :woot:

i did like this

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local HelloWorld = {}
_G.HelloWorld = HelloWorld
local NeedStartTimer = true -- toggle for timer
local StartingTime

function HelloWorld:Timer() -- this function can be called from xml <OnUpdate>
    if (NeedStartTimer == true) then -- if timer not started yet, doing here
        NeedStartTimer = false
        StartingTime = GetTime() -- remembering time when timer started
    end
    if (NeedStartTimer == false and GetTime() - StartingTime > 5) then -- if has passed 5 seconds, doing all we need
        DEFAULT_CHAT_FRAME:AddMessage("BINGOOOOOOOOOOO!")
        NeedStartTimer = true
    end
end
and it doesn't depend on framerate :D

20

Friday, July 31st 2009, 11:44am

1 more little question:

What event will be triggered, if i write something in chat with slash? like /start or /config


i tryed some chat event, but it doesn't work...