CWDG论坛-专业魔兽插件's Archiver

Leonidas 发表于 2007-9-24 11:47

如何实现点击按钮调用自定义的函数

小弟最近初学插件,参考猫扑puilding大大的帖子,略微修改了一下,具体如下:
BossMacro.xml[code]
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
    <Script file="BossMacro.lua" />
    <Button name="Macrobutton" parent="Minimap">
        <Size>
            <AbsDimension x="30" y="30" />
        </Size>
        <Anchors>
            <Anchor point="CENTER" relativeTo="Minimap" relativePoint="CENTER">
                <Offset>
                    <AbsDimension x="-55" y="-55"/>
                </Offset>
            </Anchor>
        </Anchors>
        <NormalTexture file="Interface\AddOns\BossMacro\bm.tga"/>
        <Scripts>
            <OnLoad>
                this:Show();
            </OnLoad>
            <OnClick>
                saySomething();
            </OnClick>
        </Scripts>
    </Button>
</Ui>[/code]BossMacro.lua[code]
function saySomething()
sendChatMessage("龙会吐息,所有人及时避开火堆","SAY")
end
[/code]其实就是在小地图旁边显示一个小按钮,点击后说话,类似宏的功能

现在问题是进入游戏可以看到按钮图标正常显示,但是点击无反应,请好心人帮忙看看问题在哪儿如何

biggates 发表于 2007-9-24 12:09

在 <OnLoad> 节中加入:
this:RegisterForClicks("LeftButtonUp");

Leonidas 发表于 2007-9-24 13:57

感谢指点。现在不能试,心急啊
PS:网上很多LUA的教程,却很少有详细关于事件驱动的详细教程

Leonidas 发表于 2007-9-25 09:16

[quote]原帖由 [i]biggates[/i] 于 2007-9-24 12:09 发表 [url=http://bbs.cwowaddon.com/redirect.php?goto=findpost&pid=19820&ptid=1907][img]http://bbs.cwowaddon.com/images/common/back.gif[/img][/url]
在  节中加入:
this:RegisterForClicks("LeftButtonUp"); [/quote]
修改后还是不行=。=

simonw 发表于 2007-9-25 09:35

LeftButtonUp 默认就有不用注册的. saySomething里写的有问题. 注意大小写和中文逗号.

再试试OnMouseUp事件.

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.