PDA

View Full Version : Coding Help Please



Bidmaron
May 10th, 2009, 02:17
For those who code FG2, can I get you to take a look at the simple extension below and determine why the button isn't working right? Since I could never get an answer before when I asked more than one question, I'm keeping it to just this one question now: Why does the button graphic vanish when the button is pushed? What is supposed to happen is that when you click the button, the button down graphic replaces the original graphic and then when you let up the mouse button, the original button up graphic returns. Instead, the button graphic vanishes and neither the button down nor the button up is there. The button textwidget "Test" remains, however. If the console window is up, you will see the OnClick function printing out "clicked" when you let the button go. If you click it again after the graphic is gone, the onClick fires again, printing "clicked" into the console window. What am I doing wrong? Here is the code:


<?xml version="1.0" encoding="iso-8859-1"?>

<root version="2.0">
<properties>
<name>Programming Tools</name>
<version>1</version>

<author>Bidmaron</author>
<description>An extension with programming utilities.</description>

</properties>

<base>
<icon name="gears" file="Programming.png" />
<icon name="butn" file="button.png" />
<icon name="butn_down" file="button_down.png" />

<template name="framebutton">
<genericcontrol>
<icon>butn</icon>
<script>
function onClickDown(button,x,y)
if button == 1 then
setIcon(butn_down);
return true;
end
end
function onClickRelease(button,x,y)
if button == 1 then
setIcon(butn);
if self.onClicked then
print("have self");
self.onClicked();
else
print("no self");
end
bringToFront();
return true;
end
end
function onInit()
if label then
widget=addTextWidget("sheetlabelsmallbold",label[1]);
else
widget=addTextWidget("sheetlabelsmallbold","Okay");
end
widget.setPosition("center",0,1);
end
</script>
</genericcontrol>
</template>

<windowclass name="programlist">
<frame>storybox</frame>
<dynamic />
<datasource>debug</datasource>
<placement>
<size>
<width>275</width>
<height>350</height>
</size>
</placement>
<sizelimits>
<dynamic />
<minimum>
<width>200</width>
<height>220</height>
</minimum>
</sizelimits>
<nodelete />
<sheetdata>
<stringcontrol name="flagger">
<bounds>22,18,-22,38</bounds>
<disable />
<empty>Window Title</empty>
<nodrag />
<nodrop />
<nodragselect />
</stringcontrol>
<framebutton name="test">
<label>Test</label>
<noanchor>render</noanchor>
<bounds>-66,-42,46,27</bounds>
<script>

function onClicked()
print("clicked");
end
</script>
</framebutton>
</sheetdata>
</windowclass>

<script name="programminginit">
function onInit()
if not User.isLocal() and User.isHost() then
if DB.findNode("debug") then
DesktopManager.registerDockShortcut("gears", "gears", "Programming", "programlist", " ");
end
end
end
</script>
</base>
</root>


Attached are graphics showing the window before the first click and then the window after the first click:

Ikael
May 10th, 2009, 06:48
as a quick hunch try to change onClickDown() and onClickReleased() function's return value to nil or false. Somewhat I believe that returning true in those functions cause it to cease the processing. See FG library for more information about this theory.

Bidmaron
May 10th, 2009, 12:03
Ikael, I shall look into that. You just might be onto something, there....

Foen
May 10th, 2009, 14:40
I think you need to put the argument to setIcon in quotes. You are passing the value of the (non-existent) butn and butn_down variables to setIcon, which is equivalent to saying setIcon(nil).

As regards return values, you must return true from onClickDown for onClickReleased to be called.

Stuart

Bidmaron
May 10th, 2009, 17:26
As is often the case when I'm programming, the answer was very easy. Of course, Foen, you had it right. Problem solved.

Foen
May 10th, 2009, 17:35
No problem, easy mistake to make (I've done it countless times) and not helped by a language that allows undeclared variables to be used!

Sometimes a fresh pair of eyes helps.

I'm looking forward to seeing the fruits of your labour on this project.

Stuart

Bidmaron
May 10th, 2009, 22:46
Foen, I'm having trouble prioritizing my stuff. I bounce between working on the debugging engine and Fantasy backGrounds (the thing that runs in the background and copies over images and formattedtext, that will handle sound, and that will handle the forum extension). Making steady progress, but I'm in the middle of a move from Maine to Virginia, so I'm not getting as much time to work on things as I'd like. I have the background task reacting to updates to modules, and I can send commands to the background task and completion messages back to FG2, so it's coming along.