Jump to content




Touchpoint API


277 replies to this topic

#41 Joseph_Stalin

  • Members
  • 9 posts

Posted 21 May 2014 - 12:53 AM

I am sorry, I truly am, could I PM you because I am still having issues with all of this(Sorry I am terrible at this) and I don't want to fill up your thread with my issues.

#42 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 21 May 2014 - 02:12 AM

Feel free to start a thread over in Ask a Pro with any questions you have about it and I can help you there. :)

#43 sEi

  • Members
  • 41 posts

Posted 27 May 2014 - 09:47 AM

Hi Lyqyd

First thanks for the very nice tutorials. They for sure help me a lot getting into CC and LUA.

I have tried your example and it does not work for me.
  • I have put a computer down
  • Added a screen to the top
  • Downloaded the touchpoint script
  • Made a script with you example code
When i run the script it draw on the monitor and return to prompt and no error messages.

After testing it exits after/at this code:

Quote

t:draw()

The monitor looks like this after program run:
http://dl.dropboxuse...assorted/cc.png

I use MC: 1.7.2 and CC: 1.64pr2

What am i missing?

/sEi

#44 McLeopold

  • Members
  • 123 posts

Posted 27 May 2014 - 09:43 PM

View PostsEi, on 27 May 2014 - 09:47 AM, said:

Hi Lyqyd

First thanks for the very nice tutorials. They for sure help me a lot getting into CC and LUA.

I have tried your example and it does not work for me.
  • I have put a computer down
  • Added a screen to the top
  • Downloaded the touchpoint script
  • Made a script with you example code
When i run the script it draw on the monitor and return to prompt and no error messages.

After testing it exits after/at this code:

Quote

t:draw()

The monitor looks like this after program run:
http://dl.dropboxuse...assorted/cc.png

I use MC: 1.7.2 and CC: 1.64pr2

What am i missing?

/sEi

CC 1.6 changed the term api. In the draw function, it ends with "term.restore()" which is no longer valid.

Try this

draw = function(self)
	local prevTerm = term.redirect(self.mon)
	term.setTextColor(colors.white)
	term.setBackgroundColor(colors.black)
	term.clear()
	for name, buttonData in pairs(self.buttonList) do
		if buttonData.active then
			term.setBackgroundColor(buttonData.activeColor)
		else
			term.setBackgroundColor(buttonData.inactiveColor)
		end
		for i = buttonData.yMin, buttonData.yMax do
			term.setCursorPos(buttonData.xMin, i)
			term.write(buttonData.label[i - buttonData.yMin + 1])
		end
	end
	term.redirect(prevTerm)	
end


#45 sEi

  • Members
  • 41 posts

Posted 28 May 2014 - 10:50 AM

View PostMcLeopold, on 27 May 2014 - 09:43 PM, said:

....TRUNCATED...

CC 1.6 changed the term api. In the draw function, it ends with "term.restore()" which is no longer valid.

Try this

draw = function(self)
	local prevTerm = term.redirect(self.mon)
	term.setTextColor(colors.white)
	term.setBackgroundColor(colors.black)
	term.clear()
	for name, buttonData in pairs(self.buttonList) do
		if buttonData.active then
			term.setBackgroundColor(buttonData.activeColor)
		else
			term.setBackgroundColor(buttonData.inactiveColor)
		end
		for i = buttonData.yMin, buttonData.yMax do
			term.setCursorPos(buttonData.xMin, i)
			term.write(buttonData.label[i - buttonData.yMin + 1])
		end
	end
	term.redirect(prevTerm)	
end

That did the trick! - Now it works.

Thank you McLeopold for taking the time to help, it is much appreciated! <3

/sEi

#46 Bmandk

  • Members
  • 12 posts

Posted 02 June 2014 - 10:21 PM

I've tried out the touchpoint and it works fine, so I started on a real project for my base.

I saw the thing about the pages of buttons and decided to try it out for menus.
So I reprogrammed my control program from my terminal control to this, and ran into a problem.

The script is right here: http://pastebin.com/PmbKjbA0

The problem is on line 169 (highlighted), it will print the first line, "new1". After that it gives an error and doesn't print "new2" which is right after the table, and I'm unsure about what I am doing wrong here.
The error is:
touchpoint:104: attempt to index ? (a nil value)

I'm not that good with programming, and I looked into your code but couldn't quite figure it out. Any help is appreciated, thank you in advance!

EDIT: Something important I forgot, I am using CC 1.5

Edited by Bmandk, 02 June 2014 - 11:26 PM.


#47 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 02 June 2014 - 11:51 PM

Declaring the tables like that is calling each of those functions, right then, and putting the values those functions return into the table. Is that really what you want to be doing?

#48 Bmandk

  • Members
  • 12 posts

Posted 03 June 2014 - 12:02 AM

Oh, I didn't even think about that, I can see that now. That's not what I wanted, I just wanted to store them so I could easily put them into the buttons with a for loop. Is there another way to do this, or would I need to "manually" make every button?

#49 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 03 June 2014 - 12:45 AM

So, for the functions that don't need arguments, you can just remove the parentheses, and that will place the function value in the table. The ones that do need arguments, you can use an anonymous function. That is, instead of this:

func(args)

you'd do this:

function() func(args) end

Another issue is that your changePage function won't work as written, as it will always try to change the page to pages.page (which doesn't exist). You should change it to pages[page] and put quotes around the strings you are passing in to it, so changePage("mainMenu"), for instance.

#50 Bmandk

  • Members
  • 12 posts

Posted 03 June 2014 - 06:15 AM

Alright, thanks a bunch!

As for the pages.page, I did have it as pages[page] first, I just tried to test it out and wanted to change it back, but must've forgotten. Thanks!

#51 mckerrnel

  • Members
  • 13 posts

Posted 16 June 2014 - 02:33 AM

Not sure if this is the right place for this... I'm using this API and modified it so that the draw() function no longer does a term.clear(). It was messing up my title screen...I had a nice logo in the middle of the screen and wanted to wrap buttons around it, but the buttons kept clearing my logo. I don't know if that has a bearing on my problem though, but I suspect not.

I am trying to set a button to run an external program to update all the pastebin code associated with the system. I'm tired of quitting the main program and running it by hand and then restarting. So I set a button to run a function that calls out and reboots the computer.

local touch = touchpoint.new("left")
touch:add("Progression", nil, 2, 2, 16, 6, colors.blue, colors.lightblue)
touch:add("Upgrade", upgradeReboot, 56, 13, 69, 17, colors.blue, colors.lightblue)
-- Upgrade System Files and Reboot
function upgradeReboot()
	    touch:toggleButton("Upgrade")
	    --mlapi.tp writes the text to the terminal at location x,y and in specified colours
	    mlapi.tp("Downloading & Upgrading...standby.", 19, 17, colors.white, colors.red)
	    shell.run("update")
	    os.reboot()
end


-- MAINLINE
while true do
	    --mlapi.clear is what I use to clear the monitor screen)
	    mlapi.clear()
	    touch:draw()
	    --tppi.title is the function to draw the logo
	    tppi.title(21, 6)

	    touch:run()
end


I believe this is working, however when it re-runs the system from startup, I can no longer click on anything. Not sure why this is happening since the entire computer is rebooting?

#52 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 16 June 2014 - 02:57 AM

Which version of CC are you on? Can you post a screenshot of your setup in-game? Especially whether or not there are any other computers connected to the monitor. Also, I'd just like to confirm that you do have the program running as startup or being run from startup, correct?

#53 mckerrnel

  • Members
  • 13 posts

Posted 16 June 2014 - 04:07 AM

View PostLyqyd, on 16 June 2014 - 02:57 AM, said:

Which version of CC are you on? Can you post a screenshot of your setup in-game? Especially whether or not there are any other computers connected to the monitor. Also, I'd just like to confirm that you do have the program running as startup or being run from startup, correct?

The server is running TPPI modpack v1.0.1, which has CC 1.58. No other computers connected to the monitor. Startup runs the program, it isn't startup. I even renamed startup so it wouldn't run when I selected the button, and it does appear to work, however after it comes back from the reboot, and I run start again, the buttons are not selectable. If I break the program and run it again, they seem fine. It's weird.

Posted Image


START(UP) Program:
term.clear()
local monitor = peripheral.wrap("left")
monitor.setCursorPos(0, 0)
monitor.setTextColor(colors.white)
monitor.setBackgroundColor(colors.black)
monitor.clear()
-- mulambda165 is the actual program.
shell.run("mulambda165")

Edited by mckerrnel, 16 June 2014 - 04:09 AM.


#54 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 16 June 2014 - 04:39 AM

Hmm. If you put a sleep(1) at the top of the startup script, does it resolve the issue? The 1.57/8 builds have some odd corner cases with monitors. A sleep may help solve the issue.

#55 mckerrnel

  • Members
  • 13 posts

Posted 16 June 2014 - 04:50 AM

It's actually supposed to be around the back, but it was a pain in the butt trying to troubleshoot, so I put it to the side. I'll try the sleep and putting it at the back and see what happens. Thanks.

#56 howdanrocks

  • Members
  • 7 posts

Posted 17 June 2014 - 04:24 AM

I downloaded your api and example program to test it, but the buttons come out looking like this:

http://i.imgur.com/uJZ734v.png

Any help? Thanks!

#57 mckerrnel

  • Members
  • 13 posts

Posted 17 June 2014 - 04:29 AM

I tried both, putting the computer in the middle behind the monitor ("back"), and adding sleep(1) at the start up startup script.

It's the weirdest thing. Every OTHER time I run it, it works fine. If It reboots after clicking, it won't let me click anymore. If I break it without clicking and then run it again, it won't let me click. Breaking again and running again works fine.

#58 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 17 June 2014 - 05:46 AM

View Postmckerrnel, on 17 June 2014 - 04:29 AM, said:

I tried both, putting the computer in the middle behind the monitor ("back"), and adding sleep(1) at the start up startup script.

It's the weirdest thing. Every OTHER time I run it, it works fine. If It reboots after clicking, it won't let me click anymore. If I break it without clicking and then run it again, it won't let me click. Breaking again and running again works fine.

That is indeed very weird, and I don't think the problem is in Touchpoint at that point. I'm really not sure which way to point you at this point.

If you're feeling adventurous, could you set up a startup program that will print every event it receives and try clicking around on the monitor after a reboot?

View Posthowdanrocks, on 17 June 2014 - 04:24 AM, said:

I downloaded your api and example program to test it, but the buttons come out looking like this:

http://i.imgur.com/uJZ734v.png

Any help? Thanks!

That looks like it's trying to print an error message. Which version of ComputerCraft are you on?

Edit: If you were using 1.6+, try the new version. There was a compatibility issue that I thought I had fixed, but apparently had not yet done so. I just updated the pastebin, so use the link in the first post to get the updated version.

#59 SlimF

  • New Members
  • 1 posts

Posted 09 July 2014 - 10:15 AM

I'm using CC 1.63 and I can't get the API to work :/ I tried to modify the code with McLeopold's way, but with no succes. Can anybody please help me ?

#60 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,450 posts

Posted 09 July 2014 - 07:36 PM

The code in the first post should work fine without modification. Can you post the code you are trying to use with it and any error messages you are receiving?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users