Jump to content




Touchpoint API


277 replies to this topic

#101 GopherAtl

  • Members
  • 888 posts

Posted 07 April 2015 - 04:30 PM

View PostMechTech, on 07 April 2015 - 04:05 PM, said:

Hello I am sorry to bother you but I wanted to try your api, but I am not necessarily the best coder in the world :P
All I ask of you is to make me a small program with guidelines that will help me understand this API a bit better.
could you write me just a simple program (2 buttons that emit a redstone signal left and right) and help me understand it a little better?
Thanks.
There's an example program exactly like that in the original post, it's in a spoiler and it's fairly well commented.

#102 Kizz

  • Members
  • 99 posts
  • LocationLouisville, Kentucky

Posted 24 April 2015 - 05:54 PM

Love the API. I do have an issue where I can't break the loop in the run function. I removed the while true do from there and placed it around my t:run() in my gui program. Then I was able to easily use a button function to kill my GUI loop at the end.

I'm sure there is a way to break the loop in touchpoint from my GUI program, but I could not figure it out.

#103 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 April 2015 - 06:45 PM

Well, you could always just call error() from the button function. Or use the handleEvents method and call button functions for most of the buttons and break the loop on the exit button.

#104 Kizz

  • Members
  • 99 posts
  • LocationLouisville, Kentucky

Posted 24 April 2015 - 07:30 PM

Yea, probably a better method, but pulling the loop out has allowed me a little more comfort in how I am used to it. Plus I can easily add more to the button loop if needed, rather than passing variables about.

#105 GenuineGreatness

  • New Members
  • 2 posts

Posted 06 May 2015 - 02:36 AM

Sorry for being such a noob,

How do you make it so that one function only happens when you click the left button?
Also, how do you insert a new function for the right button?

Any help appreciated,

GG

#106 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 May 2015 - 04:26 AM

Since Touchpoint is primarily designed for use with the touchscreen monitors (which only accept one kind of click), the API accepts any kind of mouse click when it's used in a computer terminal (including middle-click!). I think someone made a modified version that passes the event to the button function, which you could then use to check which mouse button clicked it. Different functions for different mouse buttons is outside the scope of what I'd like Touchpoint to do, but you're welcome to modify it and do anything else with it under the MIT license. :)

#107 GenuineGreatness

  • New Members
  • 2 posts

Posted 06 May 2015 - 04:40 AM

Thanks!

Do you know of any other button programs/API's out there that have separate functions for each button?

#108 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 May 2015 - 05:01 AM

Not offhand, no, but there are a lot of button APIs on the forums, so it's possible someone's already made one!

#109 Cing

  • Members
  • 72 posts

Posted 10 May 2015 - 01:57 PM

Does this also works on pocket computers?

Never mind got it working

Edited by Cing, 10 May 2015 - 02:08 PM.


#110 DrWhoCrafter

  • New Members
  • 1 posts

Posted 17 May 2015 - 08:02 AM

One question, I want to use the API and want to use several monitors using a wired modem... How do i do so?

#111 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 17 May 2015 - 04:37 PM

Well, it depends on what you want each monitor to display. If you want all of them to display different things, you just make a touchpoint page instance for each monitor and add the correct buttons to each monitor's page instance. If you want them all to stay in sync, you could put all of the page instances in a table and iterate over it to make changes to all of the pages at the same time, or to have all of them transform events in turn. It might look something like:

local monitors = {
  "monitor_0",
  "monitor_1",
  "monitor_2",
}

local pages = {}

for i, side in ipairs(monitors) do
  pages[i] = touchpoint.new(side)
end

for i = 1, #pages do
  pages[i]:add("test", nil, 2, 2, 6, 6, colors.red, colors.lime)
end

while true do
  local event = {os.pullEvent()}
  for i = 1, #pages do
    event = {pages[i]:handleEvents(unpack(event))}
  end
  if event[1] == "button_click" then
    -- respond to button clicks here.
  end
end

Of course, if you really did want to use buttons with functions, it gets trickier, since you probably only want to call the button function once (and it might look something like pages[1].buttonList[event[2]].func() ), but you want any button toggling to be done on all screens, so you'd have to loop through the pages table in that button's function to toggle all of them.

Hope that helps! Feel free to post your code in Ask a Pro if you get stuck.

#112 royalcw

  • Members
  • 3 posts

Posted 02 July 2015 - 02:23 PM

For anyone, or Lyqyd, who has an idea on how to implement this. I have utilized Lyqyd's OP code to display a series of "Kits" available for new players to select.
Screenshot here: http://i1148.photobu...zpsjfmkbc4k.jpg

The code should allow the player to click on a button then grant the desired kit -> promote the player -> teleport the player. I am using a command computer to execute this plan. I can't figure out how to pass which kit was clicked on and then execute the commands for that kit/promot/teleport.

Code is here:
Spoiler

Any help is appreciated

Edited by royalcw, 02 July 2015 - 03:12 PM.


#113 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 02 July 2015 - 04:48 PM

p1 will contain the label of the button that was clicked when you get the button_click event. You can do something like this:

if event == "button_click" then
  if p1 == "Thermal Kit" then
    --# commands for thermal kit
  elseif p1 == "Thaumic Kit" then
    --# etc.
  end
end


#114 royalcw

  • Members
  • 3 posts

Posted 03 July 2015 - 12:38 PM

Thanks for the response Lyqyd. I added the if elseif statements for each check. I can't get the command computer to execute any server console commands such as /pex promote @p (promote the player who clicked the button) or /kit AE2 (gives the AE2 kit from essentials.kits plugin. I manually added the /give for each item but it doesn't actually give the items. Is there a way to execute server console commands from a ComputerCraft command computer? If there was a way then that would solve all my problems with accomplishing what happens with each button click.

The code looks like:
Spoiler

Even if a server console option doesn't exist, just having the Command Computer execute a command like "/kits AE2 @p" would be nice. This setup is for new players joining the server in a secure room. After they select a kit, they will be promoted from the default rank to player and then teleported to the regular spawnpoint for that all non-new player use.

#115 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 03 July 2015 - 07:30 PM

I'm not actually all that familiar with the command computers. You might try posting a new topic in Ask a Pro, there are a few people over there who know them pretty well. Just so you're aware though, the code above has one of the buttons named " AE2 Kit " while you're comparing against "AE2". These names will need to match for the comparison to succeed. Looks like the Miner Kit is the same way--you have spaces in the button label, but not in the string you're using to compare.

#116 royalcw

  • Members
  • 3 posts

Posted 04 July 2015 - 01:25 AM

Just wanted to share the completed working code:

Thank you for all the help Lyqyd and the amazing touchpoint API.

1. The ComputerCraft config file needed to have "enableCommandBlocks" toggled to "true" (not an obviously stated config on any other post I saw)
2. The command computer wouldn't execute any commands but a Command Block set next to the Command Computer executes everything perfectly.

The code is as follows:
Spoiler

3. The kits that are called are located in the Essentials Plugin on my kCauldron server. Players receive a backpack as well as basic items to get started in that mod.
4. New players spawn in a special room with no exits but can see this awesome monitor with buttons. After picking their kit, they are promoted to player then teleported out of the room.

Thanks again for looking at my spaghetti code!

Edited by royalcw, 04 July 2015 - 02:50 AM.


#117 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 04 July 2015 - 02:37 AM

You've still got the issue with the AE2 / AE2 Kit label mismatch, but other than that, looks pretty good. Also, be aware that pushing the non-kit buttons will still allow the promote and teleport commands to run.

#118 Nuk3_Hive

  • Members
  • 11 posts

Posted 14 July 2015 - 05:02 PM

Hey, I've made an CC code but i get this error: test:77: attemo to index? (a funtion value)

pls help me :)

Thanks <3

Code:


--Loads the API, straightforward
os.loadAPI("touchpoint")
--establish "pages" of buttons
local main = touchpoint.new("top")
local regeln = touchpoint.new("top")
local info = touchpoint.new("top")
local hilfe = touchpoint.new("top")
local allg = touchpoint.new("top")
local chat = touchpoint.new("top")
local stadt = touchpoint.new("top")

--one variable to put each page into in order to simplify switching
local t

--Two redstone testing functions
--add toggling where it makes sense
function main()
    main:toggleButton("Regeln")
    main:toggleButton("Info")
    main:toggleButton("Hilfe")
end

function regeln()
    regeln:toggleButton("Allgemein")
    regeln:toggleButton("Chat")
    regeln:toggleButton("Städte")
end
function info()
    term.clear()
    term.setCurPos(1,1)
    print("")

end

function hilfe()
    term.clear()
    term.setCurPos(1,1)
    print("")

end

function allg()
    term.clear()
    term.setCurPos(1,1)
    print("")

end

function chat()
    term.clear()
    term.setCurPos(1,1)
    print("")

end

function stadt()
    term.clear()
    term.setCurPos(1,1)
    print("")

end

-- Regeln
function regelMenu()
    t = regeln
end

---Main Menu
function mainTable()
    t = main
end

--set up two pages
do


    main:add("Regeln", regelMenu, 5, 2, 20, 6)
    main:add("Info", info, 5, 2, 20, 6)
    main:add("Hilfe", hilfe, 5, 2, 20, 6)


    regeln:add("Allgemein", allg, 5, 2, 20, 6)
    regeln:add("Chat", chat, 5, 2, 20, 6)
    regeln:add("Städte", stadt, 5, 2, 20, 6)
  
  
end

--Starts with the main Table, then checks for buttons clicked, toggles them, and runs the program it has with my modified t:run2()
mainTable()
while true do
    t:draw()
    -- local event, p1, p2, p3 = os.pullEvent() ---monitor_touch, side, xpos, ypos
    local event, p1 = t:handleEvents(os.pullEvent())   ---button_click, name
    if event == "button_click" then
	    --remove toggling and simplify button running
	    t.buttonList[p1].func()
    end
end


#119 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 14 July 2015 - 06:47 PM

You've named both a function and a touchpoint instance "main". You'll need to change one or the other to a different name. All of your other touchpoint instances and functions have the same problem.

#120 Nuk3_Hive

  • Members
  • 11 posts

Posted 15 July 2015 - 04:33 PM

View PostLyqyd, on 14 July 2015 - 06:47 PM, said:

You've named both a function and a touchpoint instance "main". You'll need to change one or the other to a different name. All of your other touchpoint instances and functions have the same problem.

Thank you but i want that the Buttons go to the funktion if i clicked them





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users