Jump to content




Touchpoint Api

api help computer

  • You cannot reply to this topic
7 replies to this topic

#1 Mauroalej36

  • Members
  • 4 posts

Posted 08 September 2014 - 07:10 AM

Hello everybody!

I am a new in compuercraft, i have installed Tekkit few eeks ago and im trying to place a monitor with 4 buttons, 3 for redstone signal and 1 for on/off the another 3. I really understand just a little of programation, i am so confuse with comands, so i decided to ask for help here in the forum. i searched alot here and did not find something like my problem but i found this topic i readed and i test, then i change the buttons locations and size.

I have this

Quote

--# load the touchpoint API
os.loadAPI("touchpoint")

--# intialize a new button set on the top monitor
local t = touchpoint.new("top")

--# add two buttons
t:add("left", nil, 4, 4, 12, 6, colors.red, colors.lime)
t:add("right", nil, 16, 4, 25, 6, colors.red, colors.lime)
t:add("back", nil, 16, 9, 25, 11, colors.red, colors.lime)


--# draw the buttons
t:draw()

while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t: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.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
rs.setOutput(p1, not rs.getOutput(p1))
end
end


Posted Image

Well i need to change the buttons labels but when i do the buttons do not send the redstone signal, i want to add a tittle in the top, and add an on/off general button. I dont know if this is hard or simple to answer just let me know if is really hard then i will leave the project.


PD: Sorry if this is a stupid or repetitive topic, i really really do not what to do whit this code.

Minecraft version 1.6.4
Computercraft version 1.58

Note: Excuse my bad English but not completely mastered the language.

#2 KingofGamesYami

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

Posted 08 September 2014 - 01:01 PM

Tables.
local tSides = {
  "Button_Label" = "right", --#change "Button_Label" to the custom label you give your button!
  "Another_Button" = "left",
  "Third_Button" = "back",
}
and change this part:
rs.setOutput( p1, not rs.getOuput( p1 ) )
to this:
rs.setOutput( tSides[ p1 ], not rs.getOutput( tSides[ p1 ] ) --#tSides[ p1 ] returns the value of that key in the table, which happens to be the side!


#3 Mauroalej36

  • Members
  • 4 posts

Posted 08 September 2014 - 02:36 PM

Thank you for the response!!!!! :D

According to what I understand the code would look like

--# load the touchpoint API
os.loadAPI("touchpoint")

--# intialize a new button set on the top monitor
local t = touchpoint.new("top")

--# add two buttons
t:add("left", nil, 4, 4, 12, 6, colors.red, colors.lime)
t:add("right", nil, 16, 4, 25, 6, colors.red, colors.lime)
t:add("back", nil, 16, 9, 25, 11, colors.red, colors.lime)

[b]local tSides = {[/b]
[b]  "Button1" = "right", --#change "Button_Label" to the custom label you give your button![/b]
[b]  "Button2" = "left",[/b]
[b]  "Button3" = "back",[/b]
[b]} [/b]

--# draw the buttons
t:draw()

while true do
        --# handleEvents will convert monitor_touch events to button_click if it was on a button
        local event, p1 = t: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.
                t:toggleButton(p1)
                --# and toggle the redstone output on that side.
[b]                rs.setOutput( tSides[ p1 ], not rs.getOutput( tSides[ p1 ][/b]
        end
end

but i am doing something wrong cause give an error

bios:339: [string"demo"] :5: ´}´ expecting (to close ´{´ at line 4)

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 08 September 2014 - 03:08 PM

That error wouldn't be generated by that code. Can you please verify that the code you're running in-game and the code posted here are exact matches? Please verify them character by character if you cannot upload the code or otherwise directly copy and paste it.

#5 Bomb Bloke

    Hobbyist Coder

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

Posted 08 September 2014 - 03:11 PM

local tSides = {
  ["Button1"] = "right", --#change "Button_Label" to the custom label you give your button!
  ["Button2"] = "left",
  ["Button3"] = "back",
}


#6 Mauroalej36

  • Members
  • 4 posts

Posted 08 September 2014 - 03:48 PM

Following your instructions i decide to put a new computer with another monitor and copy the code form 0, i have this touchpoint and i have this program from here

Quote

--# load the touchpoint API
os.loadAPI("touchpoint")

--# intialize a new button set on the top monitor
local t = touchpoint.new("top")

--# add two buttons
t:add("left", nil, 4, 4, 12, 6, colors.red, colors.lime)
t:add("right", nil, 16, 4, 25, 6, colors.red, colors.lime)
t:add("back", nil, 16, 9, 25, 11, colors.red, colors.lime)


--# draw the buttons
t:draw()

while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t: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.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
rs.setOutput(p1, not rs.getOutput(p1))
end
end

Then following recomendations i change it to this (change in bold)

Quote

--# load the touchpoint API
os.loadAPI("touchpoint")

--# intialize a new button set on the top monitor
local t = touchpoint.new("bottom")

--# add two buttons
t:add("left", nil, 4, 4, 12, 6, colors.red, colors.lime)
t:add("right", nil, 16, 4, 25, 6, colors.red, colors.lime)
t:add("back", nil, 16, 9, 25, 11, colors.red, colors.lime)

local tSides = {
["Button1"] = "right", --#change "Button_Label" to the custom label you give your button!
["Button2"] = "left",
["Button3"] = "back",
}

--# draw the buttons
t:draw()

while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t: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.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
rs.setOutput( tSides[ p1 ], not rs.getOutput( tSides[ p1 ] )
end
end

i saw this

bios:339: [string"demo"] :30: ´)´ expected (to close ´(´ at line 29)

I put another ")" here: rs.setOutput( tSides[ p1 ], not rs.getOutput( tSides[ p1 ] ) ) <----

but when i press any button

demo:29: Expected string

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 08 September 2014 - 04:03 PM

On the t:add lines, you need to make sure to set up the names to match the names in the table. For instance, if you wanted a button called "Blaze Farm" to toggle the redstone output on the left, you'd change the t:add line with "left" to say "Blaze Farm" instead, then make sure one of the entries in the table is:

["Blaze Farm"] = "left",

The names need to match exactly.

#8 Mauroalej36

  • Members
  • 4 posts

Posted 08 September 2014 - 04:22 PM

Yay guys you did it the final code is

Quote

--# load the touchpoint API
os.loadAPI("touchpoint")

--# intialize a new button set on the top monitor
local t = touchpoint.new("bottom")

local tSides = {
["Button1"] = "right", --#change "Button_Label" to the custom label you give your button!
["Button2"] = "left",
["Button3"] = "top",
}

--# add two buttons
t:add("Button1", nil, 4, 4, 12, 6, colors.red, colors.lime)
t:add("Button2", nil, 16, 4, 25, 6, colors.red, colors.lime)
t:add("Button3", nil, 16, 9, 25, 11, colors.red, colors.lime)

--# draw the buttons
t:draw()

while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t: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.
t:toggleButton(p1)
--# and toggle the redstone output on that side.
rs.setOutput( tSides[ p1 ], not rs.getOutput( tSides[ p1 ] ))
end
end

Maybe is something stupid but was hard to me.

I am very very very very grateful for your help, now i understand a little bit more of this.
Now i can finsh the proyect!!!!!! thank you all. :D :D :D :D :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users