Touchpoint API
#261
Posted 25 April 2017 - 12:01 AM
#262
Posted 25 April 2017 - 01:25 AM
I started dumping parts of my code that setup and run the buttons onto there own file to hopefully save some space on the post.
I ran this example code to make certain it produced the same error.
Only thing is, it works perfect... idk how or why but I guess it has something to do with my code (as I expected but was sure it wasnt).
Here is the code anyway:
os.loadAPI("buttonAPI") t=buttonAPI.new() local reactor100 = { " -100 ", label = "r-100" } local reactor10 = { " -10 ", label = "r-10" } local reactor5 = { " -5 ", label = "r-5" } local reactorr5 = { " +5 ", label = "r+5" } local reactorr10 = { " +10 ", label = "r+10" } local reactorr100 = { " +100 ", label = "r+100" } t:add(reactor100, nil, 1, 5, 6, 5, colors.red, colors.lime) t:add(reactor10, nil, 8, 5, 13, 5, colors.red, colors.lime) t:add(reactor5, nil, 15, 5, 20, 5, colors.red, colors.lime) t:add(reactorr5, nil, 31, 5, 36, 5, colors.red, colors.lime) t:add(reactorr10, nil, 38, 5, 43, 5, colors.red, colors.lime) t:add(reactorr100, nil, 45, 5, 50, 5, colors.red, colors.lime) t:draw() while true do local event, p1 = t:handleEvents(os.pullEvent()) if event == "button_click" then t:toggleButton(p1) end end
As it is my code, I will not waste anymore of your time, I will attempt to debug it on my own that way I can better learn from my mistakes.
Again, Thank you and have a great day/night.
#263
Posted 25 April 2017 - 04:20 PM
#264
Posted 25 April 2017 - 05:33 PM
I was able to find the bug, simply a wrong y val.
Here is my new bug
I am trying to keep my program fairly compact and would like to have certain functions within the buttons. I just want it to do some simple addition.
All works well until I actually try to run the button function via t:run(buttonName).
When I do that, it looks as though the whole program freezes, the term stops updating, buttons don't flash, ect.
currently there are no functions for the bottom row of buttons on page2 as I would like to find/fix the bug before I continue with this method.
I am quite certain that this is yet another issue with my code but I am struggling to figure it out.
I don't claim to be any good at coding, organizing said code, ect.
I would very much appreciate it If you can figure out what I did wrong.
Here is the code: https://pastebin.com/arLp6X80
Update: I tried making it so the button simply starts a function as apposed to having the function in it and still got the same bug.
Thanks and good luck.
Edited by brainytwoo, 25 April 2017 - 07:25 PM.
#265
Posted 26 April 2017 - 12:58 AM
if currentPage.buttonList[p1].func then currentPage.buttonList[p1].func() end
#266
Posted 26 April 2017 - 01:29 AM
Lyqyd, on 26 April 2017 - 12:58 AM, said:
if currentPage.buttonList[p1].func then currentPage.buttonList[p1].func() end
Wow, I had no idea, I assumed that you had to manually use the function within the buttons via t:run().
Thanks, Good to know.
I am still learning about your t.buttonList[i] thing (just discovered it today actually).
Btw, your bit of code you give there works perfect, thank you
With this last bit of info, I should be able to use your API with every touch program I have/will ever make, Thank you!
Edited by brainytwoo, 26 April 2017 - 01:29 AM.
#267
Posted 04 August 2017 - 05:19 AM
using this in my BigReactors program for an on and off buttons. I noticed that the buttons in the examples work in the computer... what if you want it on the monitor itself?
while im at it is there a way i can take this code into like an if else statement with the 2 buttons being if and that code being else so if one is being used the other wont be used? Kinda like an override type thing
Edited by KoopaTheTurtle, 04 August 2017 - 05:20 AM.
#268
Posted 14 August 2017 - 09:16 PM
Blank Slate -> Blank
Slate
#269
Posted 14 August 2017 - 10:00 PM
Lyqyd, on 16 August 2013 - 09:58 PM, said:
A note: One can also fully specify the text characters of the button by providing a table for the label. The table should contain exactly the text of the button, in numerical indices, top to bottom. Each index should be as long as the button is wide. A label entry should be present in the table, which should be a single string to be used as the name of the button. For example:
local buttonName = { " ", " A button ", " label ", " ", label = "a button" } t:add(buttonName, nil, 2, 2, 11, 5, colors.red, colors.lime)
#270
Posted 16 August 2017 - 07:16 PM
Im using the example that was give in the spoiler. Im trying to switch left to on and right to off but when i do this i can click the button multiple times.
How do i change the names of the buttons (whats displayed) and still be able to mass click the buttons?
#271
Posted 13 November 2017 - 02:16 AM
--# load the touchpoint API os.loadAPI("touchpoint") local width,height = term.getSize() local buttonWidth = math.floor((width-2)*0.5) --local buttonWidth = width local buttonHeight = 1 --# intialize a new button set on the top monitor local topBar = touchpoint.new() --# add two buttons topBar:add("goto", nil, 1, 1, buttonWidth, buttonHeight) topBar:add(" ",nil,buttonWidth,1,3,buttonHeight,colors.white,colors.red) topBar:add("come", nil, buttonWidth+1, 2, buttonWidth, buttonHeight) --# draw the buttons topBar:draw() while true do --# handleEvents will convert monitor_touch events to button_click if it was on a button local event, p1 = topBar:handleEvents(os.pullEvent()) if event == "button_click" then --# p1 will be "left" or "right", since those are the button labels --# toggle the button that was clicked. topBar:toggleButton(p1) --# and toggle the redstone output on that side. --rs.setOutput(p1, not rs.getOutput(p1)) end end
#272
Posted 13 November 2017 - 04:54 AM
name, [func], xMin, yMin, xMax, yMax [, inactiveColor] [, activeColor] [, inactiveText] [, activeText]
If you wanted a button to start in column 10 and have a width of 5, then you'd set xMin to 10 and xMax to 14.
You've set yMax for all of your buttons to 1, so none can extend down past the top row.
#273
Posted 02 January 2018 - 07:12 PM
I use a slightly modified version of your api which is extended by a clear and getState function. My version can be found here: https://pastebin.com/4eCwR0Dk
When the server restarts I get the following error message on all computers running the touchpoint api:
touchpoint:96: attempt to index ? (a nil value)after a manual computer restart everything is fine. But the process of starting every single computer manually is annoying.
In this line the following code is written:
if self.clickMap[i][j] ~= nil thenwhen i add the following print (line 3 of the following code snippet)
for i = xMin, xMax do for j = yMin, yMax do print("i: ", i, " j: ", j) if self.clickMap[i][j] ~= nil then --undo changesand restart the server, I get this error message:
go-monitor:14: attempt to concatenate string and nilwhich says that either i or j is nil in the for loop. I do not have any clue why this can happen...
When i print xMin, xMax, yMin and yMax I get this result:
xMin: 8 xMax: 28 yMin: 1 yMax: 3 touchpoint:98: attempt to index ? (a nil value)so there must be a issue with the for loops... (cause I used to prints the line 96 of above is now 98)
//EDIT:
It becomes very strange, when i just print the variables without concatenation the last prints before the error ist
17 3 18 1 18 2 18 3 19 1 touchpoint:103: attempt to index ? (a nil value)it always stops after 19 and 1 on this computer even after a few server restarts.
Ok, my last guess might be that in the new-function this line might makes trouble:
local x, y = buttonInstance.mon.getSize()If anyone has an idea why this is happening or having the same issue, I would be very glad about an answer.
//EDIT 2:
I got the issue. The following line is causing the trouble:
local x, y = buttonInstance.mon.getSize()If I set x and y manually to 100 everything works fine. Seems that the monitor size is wrong at server startup (maybe connected monitors are not recognized correctly). Anyone an idea how to solve this?
//EDIT3:
With these information a was able to find this thread: http://www.computerc...-on-first-load/
I think my mistake is the following, even though I do not know how to fix it in a nice way:
local t = touchpoint.new("monitor_4") t.mon.setTextScale(.5)I initialize the api with the default monitor text scale. Reducing this probably increases the amount of pixels in each direction and therefore the returned values of mon.getSize(). This might cause this issue.
Thanks and best regards
Patrick
Edited by Patistar, 02 January 2018 - 08:24 PM.
#274
Posted 02 January 2018 - 08:12 PM
Patistar, on 02 January 2018 - 07:12 PM, said:
I use a slightly modified version of your api which is extended by a clear and getState function. My version can be found here: https://pastebin.com/4eCwR0Dk
When the server restarts I get the following error message on all computers running the touchpoint api:
touchpoint:96: attempt to index ? (a nil value)after a manual computer restart everything is fine. But the process of starting every single computer manually is annoying.
Sounds like it could be something with chunk boundries, is the program using peropherals? if it is then make sure that the peripheral is in the same chunk as the computer.
Alternatively, put a sleep(1) at the start of the program so that the world can 'settle' before the program does things.
Edited by Lupus590, 02 January 2018 - 08:22 PM.
#275
Posted 02 January 2018 - 08:47 PM
So if anyone having a similar issue:
The solution is that the text scale of the monitor is not allowed to be changed after the touchpoint api is initialized.
As you can see in the pastebin above, i fixed it the way I gave the new function a second optional parameter textScale. If the textScale is not nil (and therefore set) and monSide is given (and therefore a monitor and not the terminal is used), I set the textScale in the new function.
Thanks to the forum to listen so patiently to my issues and helping me to fix it. Also thanks for your answer, Lupus. I did know this is a issue and build a check to ensure the peripheral is connected to the computer before booting the program.
Have a nice day, best regards
Patrick
#276
Posted 05 February 2018 - 05:35 AM
#277
Posted 05 February 2018 - 10:17 AM
kain184, on 05 February 2018 - 05:35 AM, said:
See below.
Edited by Lupus590, 10 February 2018 - 03:08 PM.
#278
Posted 10 February 2018 - 02:28 AM
t.buttonList
So, if you know your button label, testing for active state is:
if t.buttonList[label].active then
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users