Jump to content




Touchpoint API


277 replies to this topic

#261 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 April 2017 - 12:01 AM

Please post the code you're using.

#262 brainytwoo

  • Members
  • 15 posts

Posted 25 April 2017 - 01:25 AM

Hello, sorry it took me so long to get back, i didnt realize that your post would start a new page, my bad.

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 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 April 2017 - 04:20 PM

Feel free to post the full code either here or in Ask a Pro if you're struggling to figure out the issue. This API is known fairly well by several other members on the forum, so it shouldn't be hard to get another set of eyes looking at the issue.

#264 brainytwoo

  • Members
  • 15 posts

Posted 25 April 2017 - 05:33 PM

Thanks much!

I was able to find the bug, simply a wrong y val.

Here is my new bug :D
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 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 26 April 2017 - 12:58 AM

You can't mix :run() and :handleEvents(). Instead of the run call, try:

if currentPage.buttonList[p1].func then
  currentPage.buttonList[p1].func()
end


#266 brainytwoo

  • Members
  • 15 posts

Posted 26 April 2017 - 01:29 AM

View PostLyqyd, on 26 April 2017 - 12:58 AM, said:

You can't mix :run() and :handleEvents(). Instead of the run call, try:

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 KoopaTheTurtle

  • Members
  • 5 posts
  • LocationNew Zealand

Posted 04 August 2017 - 05:19 AM

heyhey

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
Spoiler

Edited by KoopaTheTurtle, 04 August 2017 - 05:20 AM.


#268 AT2035 Microphone

  • New Members
  • 1 posts

Posted 14 August 2017 - 09:16 PM

So if I for instance have button being made and my label is too long for one line of space how would i go about making the part of the label move to the next line for instance:

Blank Slate -> Blank
Slate

#269 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 14 August 2017 - 10:00 PM

View PostLyqyd, on 16 August 2013 - 09:58 PM, said:

-snip-
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 KoopaTheTurtle

  • Members
  • 5 posts
  • LocationNew Zealand

Posted 16 August 2017 - 07:16 PM

Okay i have the buttons working on the monitors now.
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 jaspercayne

  • Members
  • 3 posts

Posted 13 November 2017 - 02:16 AM

I'm going nuts trying to figure out how to use this on a pocket computer. I keep seeing mentions of it being possible, or "Nevermind, I got it", but not once have I seen an actual method to do so. The buttons do not seem to want to display properly, no matter how I arrange the coordinates they are placed at, nor can I seem to create buttons on anything that isn't the top line (y=1). In addition to this, I cannot seem to get anything but the first button to actually catch a click event? I haven't gone through the API itself to see if I need to adjust anything yet, but I assumed it should just work since I am keeping everything within the dimensions of the pocket computer and initialized a new touchpoint instance without any arguments to tell it to attach to anything. Anyone care to give a hand figuring out how to get this working on a pocket computer?

--# 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 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 13 November 2017 - 04:54 AM

The parameters for "add" are:

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 Patistar

  • Members
  • 13 posts

Posted 02 January 2018 - 07:12 PM

Hello,
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 then
when 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 changes
and restart the server, I get this error message:
go-monitor:14: attempt to concatenate string and nil
which 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 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 02 January 2018 - 08:12 PM

View PostPatistar, on 02 January 2018 - 07:12 PM, said:

Hello,

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 Patistar

  • Members
  • 13 posts

Posted 02 January 2018 - 08:47 PM

Okay, as it is usually when you try fixing stuff. Had this problem for almost half a year now trying to fix it every now and then. Never found a solution. Today I decided to ask my question here and therefore did structured debugging writing my results down in this forum. And less than 2 hours later I found the issue and fixed it.

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 kain184

  • Members
  • 72 posts

Posted 05 February 2018 - 05:35 AM

how can i access data in the button table inside the api. i want to test if one of the buttons is on or not.

#277 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 05 February 2018 - 10:17 AM

View Postkain184, on 05 February 2018 - 05:35 AM, said:

how can i access data in the button table inside the api. i want to test if one of the buttons is on or not.

There is no way to do this, you will have to either modify the API or track every button state yourself.

See below.

Edited by Lupus590, 10 February 2018 - 03:08 PM.


#278 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 10 February 2018 - 02:28 AM

Huh? No, your instance's button table is inside it. So, if your instance was named "t", the list is at:

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