Log in

View Full Version : Visibility of template functions



Brenn
March 17th, 2012, 21:16
I'm creating a control at runtime from a template. When I try to call a function contained within that template's script I get an error:

"Script Error: [string "scripts/ore_radial.lua"]:29: attempt to call field 'setParentValues' (a nil value)"

Here is the template xml:


<template name="oreradialcontrol">
<genericcontrol>
<frame>
<name>oreradialbutton</name>
<offset>0,0,0,0</offset>
</frame>
<bounds>0,0,50,50</bounds>
</genericcontrol>
<script file="scripts/ore_radial_control.lua" />
</template>


Here is the template's lua:


myIndex = 0;
myCallback = nil;

function setParentValues(index, callback)
myIndex = index;
myCallback = callback;
end

function onClickRelease(button,x,y)
myCallback(myIndex);
end

and here is the code that calls it


function createButtons(num)
local angInc = math.rad(360/num);
for i = 1, table.getn(myMenuTable.items) do
local currItem = myMenuTable.items[i];
local bx = 125 + math.cos(angInc*(currItem.position-1))*buttonOffset;
local by = 125 + math.sin(angInc*(currItem.position-1))*buttonOffset;
myButtons[i] = createControl("oreradialcontrol",("orb"..i));
myButtons[i].setStaticBounds(bx, by, 50, 50);
local widget = myButtons[i].addTextWidget(currItem.font,currItem.text);
myButtons[i].setTooltipText(currItem.tooltip);
myButtons[i].setParentValues(i,OreMenu.onMenuSelection);
end
end

I'm just fooling around with creating my own radial menu with the rest of that. Now it calls the base window control methods (..setTooltipText, etc) just fine, however it hits a snag on the function I described in the script. I'm completely stumped.

Anyone have a clue what's going on here?

Brenn
March 18th, 2012, 01:30
Nevermind

It always helps to actually have <script> inside the control tags.

I come up with some incredibly stupid ways to waste time.:mad: