Jump to content




Touchpoint API


277 replies to this topic

#61 Livewire13

  • Members
  • 13 posts

Posted 17 July 2014 - 03:11 PM

When running the example program on a monitor connected via wired modem, I get this error:
"touchpoint:139: attempt to index ? (a nil value)

When I run the example program on a monitor attached directly to the computer, it works just fine.
I looked at the API line 139 and it looks like it's having trouble getting the size of a monitor connected via wired modem. Could this be fixed?

Edited by Livewire13, 17 July 2014 - 03:13 PM.


#62 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 17 July 2014 - 03:36 PM

Could you post the code you're using, please?

#63 Livewire13

  • Members
  • 13 posts

Posted 17 July 2014 - 03:47 PM

It's the example code on the OP but here it is:
Spoiler


#64 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 17 July 2014 - 04:37 PM

Did you change the side/peripheral name argument from "top" to the name of the connected monitor when you were trying to use a wired modem? You will need to use the peripheral name that was displayed in chat when you activated the modem attached to the monitor.

#65 Livewire13

  • Members
  • 13 posts

Posted 17 July 2014 - 05:17 PM

Woops! I had typed monitor_02 instead of monitor_2 in the program. All works fine now!

Edited by Livewire13, 17 July 2014 - 05:22 PM.


#66 Verdandi

  • New Members
  • 2 posts

Posted 21 July 2014 - 09:29 PM

Hey Lyqyd, I'm totally new to this programming stuff (started yesterday) :) And it's quite hard for me to get used to it. My ultimate goal (and the reason why I started with CC) is a touchscreen controlled Wither farm using MFFS. I tired Dires API first and was not be able to make a button which sends a continuous redstone signal while its toggled. I'm pretty glad that Google brought me here, your API looks way easier to me then Dires. But I don't understand this p1 thing in your example program, I tested it and tried to rename the Buttons which blowed it up. So I would be pretty happy if you could explain me how you tied the sites with the button labels together it would help me a lot understanding this whole programming thing :)

#67 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 22 July 2014 - 02:52 AM

Well, in the example program, p1 is the first parameter of the event received from os.pullEvent, after the event passes through the handleEvents method. For Touchpoint's button_click events, that parameter is the label of the button. Since the two button names are "left" and "right", and those two strings are the names of the sides, the example script uses them directly to control the redstone output. If you change the labels, you'd want to handle the redstone output differently, most likely by comparing the label of the button clicked (p1) to the labels you actually set (like "Wither Farm") and control the redstone that way.

#68 Verdandi

  • New Members
  • 2 posts

Posted 22 July 2014 - 05:42 AM

Hm, okay, I'll look into that! Is there any tutorial for Touchpoint? I've already googled it but couldn't find anything. I would like to thank you for your advice so far. :)

#69 BeaubeauFett

  • Members
  • 13 posts

Posted 28 November 2014 - 11:58 PM

I was wondering if there was a way to have a button toggle the label of a button? instead of doing multiple instances of rename()?

Spoiler

basically I have my computer hooked up to a t flip flop that opens and closes a hidden staircase on buttonclick

without having the rename it works fine, but after that it stops the code do to an error between my program and the touchpoint api.
when I click on the monitor, it changes the screen to red and "Closed!", but then if I click it again, it still says "Closed!" but turns green and doesn't activate my redstone function.

after that it terminates the program and says:
touchpoint:117: attempt to index ? (a nil value)


#70 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 29 November 2014 - 12:22 AM

Well, you never do rename it back to "Open!". The second time you try to rename the "Open!" button to "Closed!", it can't find the button you are trying to rename ("Open!"), because you've already renamed it.

Try swapping the rename line out for this:

if p1 == "Open!" then
  t:rename("Open!", "Closed!")
elseif p1 == "Closed!" then
  t:rename("Closed!", "Open!")
end


#71 BeaubeauFett

  • Members
  • 13 posts

Posted 29 November 2014 - 02:05 AM

 Lyqyd, on 29 November 2014 - 12:22 AM, said:

Well, you never do rename it back to "Open!". The second time you try to rename the "Open!" button to "Closed!", it can't find the button you are trying to rename ("Open!"), because you've already renamed it.

Try swapping the rename line out for this:

if p1 == "Open!" then
  t:rename("Open!", "Closed!")
elseif p1 == "Closed!" then
  t:rename("Closed!", "Open!")
end

Thank you, I had tried a couple different methods to swap the name back and forth, but the main thing was I couldn't figure out if you could check for the button label. I'll do that code and try it out.

EDIT: It worked, thanks a bunch! :D

Edited by BeaubeauFett, 29 November 2014 - 02:13 AM.


#72 BeaubeauFett

  • Members
  • 13 posts

Posted 29 November 2014 - 09:55 AM

Is there possibly a way to make this setup the same buttons on 2 different monitors (access the same exact coding from 2 different monitors?)

EDIT: for example I have just:

local t = touchpoint.new("top")

but i'm looking for something like this (I've tried this one and it doesn't work lol)

local t = touchpoint.new("top", "monitor_5")

I've gotten both monitors to work individually, but I can't get them to run the same info together.

Edited by BeaubeauFett, 29 November 2014 - 08:31 PM.


#73 BeaubeauFett

  • Members
  • 13 posts

Posted 02 December 2014 - 12:55 AM

Any help here? lol.

#74 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 02 December 2014 - 01:07 AM

I think the best thing to do would be to just use two different page instances and have changes made to one affect the other. So if one monitor's button gets clicked, you'd toggle both monitor's buttons and toggle the output. There isn't really a built-in way to do this.

#75 BeaubeauFett

  • Members
  • 13 posts

Posted 02 December 2014 - 03:41 AM

So essentially have each monitor on a different page, but when the button is pressed it affects both pages?

e.i.

os.loadAPI("touchpoint")

local page1 = touchpoint.new("top")
local page2 = touchpoint.new("monitor_5")

page1:add("Open!", nil, 1, 1, 5, 5, colors.lime, colors.red)
page2:add("Open!", nil, 1, 1, 5, 5, colors.lime, colors.red)

--toggle buttons on both screens and activate redstone.
function tog()
  page1:toggleButton()
  page2:toggleButton()
  rs.setOutput("back", true)
  sleep(1)							  --to give time for redstone to finish action
  rs.setOutput("back", false)
end

--activate tog() on button click.
while true do
  page1:draw()
  page2:draw()
  local event, p1 = t:handleEvents(os.pullEvent())
  if event == "button click" then
	tog()
	if p1 == "Open!" then  --rename the buttons on click
	  page1:rename("Open!", "Closed!")
	  page2:rename("Open!", "Closed!")
	elseif p1 == "Closed!" then
	  page1:rename("Closed!", "Open!")
	  page2:rename("Closed!", "Open!")
	end
  end
end

you think that looks about right?

Edited by BeaubeauFett, 02 December 2014 - 03:48 AM.


#76 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 02 December 2014 - 05:43 AM

The t:handleEvents part won't work. You'd need to handle events from both monitors, so it'd be:

local event, p1 = page1:handleEvents(page2:handleEvents(os.pullEvent()))


#77 BeaubeauFett

  • Members
  • 13 posts

Posted 02 December 2014 - 02:13 PM

ok, Thank you, i'll check this out and hopefully it works :D

#78 Chillic_

  • New Members
  • 2 posts

Posted 23 December 2014 - 05:05 PM

Hello Lyqyd!

First of all, love you api!
It was my first time programming something so I'm not so good in that...

But is there a way in this api to remove your buttons again?

#79 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,454 posts

Posted 24 December 2014 - 04:58 AM

You know, I'd have to agree, that was kind of missing. I've just added a remove function. If you had a button named "foo" that you wanted to remove from the touchpoint page t, a quick t:remove("foo") will do so with the latest version of the API, found at the same pastebin code.

#80 Chillic_

  • New Members
  • 2 posts

Posted 25 December 2014 - 11:25 AM

A really huge thanks dude!





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users