Bug: Button OnClick not detecting clicks #103

Closed
opened 2023-12-31 04:20:22 +08:00 by Tarkz · 4 comments
Tarkz commented 2023-12-31 04:20:22 +08:00 (Migrated from github.com)

I've installed basalt and set up my first program following the tutorial.
I've set up a button by using

local btnGate = controlfram
:addButton()
:setPosition(2,2)
:setText("[ OPEN ]")
:setBackground(colors.yellow)

I originally had the onclick set up as part of the call chain, but have movied it to be it's own section

btnGate:onClick(function(self,event,button,x,y)
basalt.debug("CLICK EVENT")
if (event == "mouse_click") and (button == 1) then
basalt.debug("CLICKED")
open("gate") --My function call for my gates
end
end)

after this I have the basalt.autoUpdate() call.
The program starts up, and I can drag the movableframe around like it's supposed to, but clicking a button never does anything. And the debug events are never called. I'm not sure why.

Checklist

[ X] I am running the latest version.

I've installed basalt and set up my first program following the tutorial. I've set up a button by using > local btnGate = controlfram > :addButton() > :setPosition(2,2) > :setText("[ OPEN ]") > :setBackground(colors.yellow) I originally had the onclick set up as part of the call chain, but have movied it to be it's own section >btnGate:onClick(function(self,event,button,x,y) > basalt.debug("CLICK EVENT") > if (event == "mouse_click") and (button == 1) then > basalt.debug("CLICKED") > open("gate") --My function call for my gates > end >end) after this I have the basalt.autoUpdate() call. The program starts up, and I can drag the movableframe around like it's supposed to, but clicking a button never does anything. And the debug events are never called. I'm not sure why. **Checklist** [ X] I am running the latest version.
piprett commented 2023-12-31 04:29:41 +08:00 (Migrated from github.com)

It appears that basalt.debug is a bit broken. However, the code below works on my machine:

local basalt = require("basalt")
local main = basalt.createFrame()

local btnGate = main
  :addButton()
  :setPosition(2,2)
  :setText("[ Shutdown ]")
  :setBackground(colors.yellow)
  :onClick(function(self, event, button, x, y)
    os.shutdown()
  end)

basalt.autoUpdate()

Be sure to update os.shutdown() with something more useful, like your function open("gate")

It appears that `basalt.debug` is a bit broken. However, the code below works on my machine: ```lua local basalt = require("basalt") local main = basalt.createFrame() local btnGate = main :addButton() :setPosition(2,2) :setText("[ Shutdown ]") :setBackground(colors.yellow) :onClick(function(self, event, button, x, y) os.shutdown() end) basalt.autoUpdate() ``` Be sure to update `os.shutdown()` with something more useful, like your function `open("gate")`
Tarkz commented 2023-12-31 05:03:16 +08:00 (Migrated from github.com)

It appears that basalt.debug is a bit broken. However, the code below works on my machine:

local basalt = require("basalt")
local main = basalt.createFrame()

local btnGate = main
  :addButton()
  :setPosition(2,2)
  :setText("[ Shutdown ]")
  :setBackground(colors.yellow)
  :onClick(function(self, event, button, x, y)
    os.shutdown()
  end)

basalt.autoUpdate()

Be sure to update os.shutdown() with something more useful, like your function open("gate")

I took out the debugs and tried it with the os.shutdown() and confirmed that worked. I put back in my open("gate") function and it seems to run the function, but skips over the rednet broadcast call.

rednet.broadcast("open","Gatekeeper")

is there something else I have to do to have basalt broadcast rednet commands?

> It appears that `basalt.debug` is a bit broken. However, the code below works on my machine: > > ```lua > local basalt = require("basalt") > local main = basalt.createFrame() > > local btnGate = main > :addButton() > :setPosition(2,2) > :setText("[ Shutdown ]") > :setBackground(colors.yellow) > :onClick(function(self, event, button, x, y) > os.shutdown() > end) > > basalt.autoUpdate() > ``` > > Be sure to update `os.shutdown()` with something more useful, like your function `open("gate")` I took out the debugs and tried it with the os.shutdown() and confirmed that worked. I put back in my open("gate") function and it seems to run the function, but skips over the rednet broadcast call. > rednet.broadcast("open","Gatekeeper") is there something else I have to do to have basalt broadcast rednet commands?
Tarkz commented 2023-12-31 05:05:19 +08:00 (Migrated from github.com)

It appears that basalt.debug is a bit broken. However, the code below works on my machine:

local basalt = require("basalt")
local main = basalt.createFrame()

local btnGate = main
  :addButton()
  :setPosition(2,2)
  :setText("[ Shutdown ]")
  :setBackground(colors.yellow)
  :onClick(function(self, event, button, x, y)
    os.shutdown()
  end)

basalt.autoUpdate()

Be sure to update os.shutdown() with something more useful, like your function open("gate")

I took out the debugs and tried it with the os.shutdown() and confirmed that worked. I put back in my open("gate") function and it seems to run the function, but skips over the rednet broadcast call.

rednet.broadcast("open","Gatekeeper")

is there something else I have to do to have basalt broadcast rednet commands?

In case it helps the open("gate") function is:

function open(sTarget)
if sTarget == "gate" then
rednet.broadcast("open", "Gatekeeper")
end
end

A really simple function for now. And I have the rednet.broadcast() call working when I use a pocket computer with the basic lua terminal as well as other CC based programs.

> > It appears that `basalt.debug` is a bit broken. However, the code below works on my machine: > > ```lua > > local basalt = require("basalt") > > local main = basalt.createFrame() > > > > local btnGate = main > > :addButton() > > :setPosition(2,2) > > :setText("[ Shutdown ]") > > :setBackground(colors.yellow) > > :onClick(function(self, event, button, x, y) > > os.shutdown() > > end) > > > > basalt.autoUpdate() > > ``` > > > > > > > > > > > > > > > > > > > > > > > > Be sure to update `os.shutdown()` with something more useful, like your function `open("gate")` > > I took out the debugs and tried it with the os.shutdown() and confirmed that worked. I put back in my open("gate") function and it seems to run the function, but skips over the rednet broadcast call. > > > rednet.broadcast("open","Gatekeeper") > > is there something else I have to do to have basalt broadcast rednet commands? In case it helps the open("gate") function is: >function open(sTarget) > if sTarget == "gate" then > rednet.broadcast("open", "Gatekeeper") > end >end A really simple function for now. And I have the rednet.broadcast() call working when I use a pocket computer with the basic lua terminal as well as other CC based programs.
Tarkz commented 2023-12-31 10:25:00 +08:00 (Migrated from github.com)

I did get a redstone command to work from my Advanced Pocket Computer using the Basalt UI. So I just have to assume the issue is with my program on the Advanced Computer controlling the gate. Thank you for the help with the basalt.debug() earlier.

I did get a redstone command to work from my Advanced Pocket Computer using the Basalt UI. So I just have to assume the issue is with my program on the Advanced Computer controlling the gate. Thank you for the help with the basalt.debug() earlier.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: GitHub/Basalt#103
No description provided.