This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Cing's profile picture

NumberPad API with Lyqyd's touchpoint APi

Started by Cing, 23 April 2015 - 03:57 PM
Cing #1
Posted 23 April 2015 - 05:57 PM
Hi CC'ers

I'am currently working at API which automaticlly makes a numberpad of buttons.

Using Lyqyd touchpoint api: http://pastebin.com/pFHeia96
go here for more information: http://www.computerc..._hl__touchpoint

Here is the API: http://pastebin.com/6Sxt6ass (MAN THAT PASTE :lol:/> :lol:/>) Update: http://pastebin.com/SG2dU6eU
and a test program using it: http://pastebin.com/ftZp1Z0e Update: http://pastebin.com/Ey8jWUJA

But i have 2 problems.
The first problem is at line 4 of the Api i get attempt to index? (a nil value).
I don't get why it isn't working because it worked fine when i put it in the test program.

And the second problem i have is that the buttons don't get drawn on the monitor.
Edited on 24 April 2015 - 11:51 AM
Dragon53535 #2
Posted 23 April 2015 - 06:08 PM
First thing i'm noticing (Not your error), but the buttons I think

Is that in your api you have

t = touchpoint.new("right")
and in your program you have

local t = touchpoint.new("right")
Your program, will ONLY see the local t, so at the bottom when you call setNumberPad.numberPad, your api is using the global t, or the one that it has access to. It then draws buttons and such. and then when that's done. YOU draw the empty local t in your test program.


Also, in your API you will NEVER have rainbow colors. since you haven't defined rainbow. I'm guessing you want to do

if colorActive == "rainbow" then



Edit: Derp just realized why you get your error.

Apis don't get access to shell, so shell.run doesn't exist. that's why you're erroring. Try this for getting your file:


local s = loadfile("/rom/programs/pastebin")
s("get","pFHeia96","touchpoint")
Dunno if that will exactly work, but might.

Edit2: Derp thanks yami, i fixed it on this post now… Why didn't I actually think of that lol
Edited on 23 April 2015 - 05:19 PM
KingofGamesYami #3
Posted 23 April 2015 - 06:15 PM
That last bit of code won't work, it'd work if you did this:


local s = loadfile( "/rom/programs/pastebin" )
s( "get", "pFHeia96", "touchpoint" )

However, you should really use http.get directly.
Cing #4
Posted 23 April 2015 - 08:56 PM
First thanks for the quick respons

Second thing
Also, in your API you will NEVER have rainbow colors. since you haven't defined rainbow. I'm guessing you want to do

if colorActive == "rainbow" then
If you look in my API you will see that i already did that.

This is how it looks like:


Third thing
That last bit of code won't work, it'd work if you did this:


local s = loadfile( "/rom/programs/pastebin" )
s( "get", "pFHeia96", "touchpoint" )

However, you should really use http.get directly.
Thanks for the tip i will look in to that.

Fourth thing
I have tried a lot of possible compositions but non work good.

EDIT1:
KingofGamesYami i have looked in to http.get but i am not really sure how i should use it.
Could you make a example?

EDIT2:
If have tried:

local s = loadfile( "/rom/programs/pastebin" )
s( "get", "pFHeia96", "touchpoint" )
but this also doesn't work.
Edited on 24 April 2015 - 05:36 PM
Dragon53535 #5
Posted 23 April 2015 - 09:48 PM
First thanks for the quick respons

Second thing
Also, in your API you will NEVER have rainbow colors. since you haven't defined rainbow. I'm guessing you want to do

if colorActive == "rainbow" then
If you look in my API you will see that i already did that.

EDIT2:
If have tried:

local s = loadfile( "/rom/programs/pastebin" )
s( "get", "pFHeia96", "touchpoint" )
but this also doesn't work.
Two things, one. In your API, you do not already have that rainbow. If you notice in your api you have the line

if colorActive == rainbow then
--# I gave you
if colorActive == "rainbow" then
Those are two different things, yours tries to find a variable named rainbow (There isn't one, so it's nil), and mine checks to see if you set it to text saying rainbow.

Second. Just swap over the if statement for the touchpoint api into your test code, rather than your api.
KingofGamesYami #6
Posted 23 April 2015 - 10:00 PM
Here's a quick example of http.get (using touchpoint)


local h = http.get( "http://pastebin.com/raw.php?i=pFHeia96" ) --#get the raw paste
if h then
  local f = fs.open( "touchpoint", "w" ) --#open the 'touchpoint' file in write mode
  f.write( h.readAll() ) --#write the contents of the raw paste to the file
  f.close() --#close the file handle
  h.close() --#close the web handle
end
Cing #7
Posted 23 April 2015 - 10:22 PM
First thanks for the quick respons

Second thing
Also, in your API you will NEVER have rainbow colors. since you haven't defined rainbow. I'm guessing you want to do

if colorActive == "rainbow" then
If you look in my API you will see that i already did that.

EDIT2:
If have tried:

local s = loadfile( "/rom/programs/pastebin" )
s( "get", "pFHeia96", "touchpoint" )
but this also doesn't work.
Two things, one. In your API, you do not already have that rainbow. If you notice in your api you have the line

if colorActive == rainbow then
--# I gave you
if colorActive == "rainbow" then
Those are two different things, yours tries to find a variable named rainbow (There isn't one, so it's nil), and mine checks to see if you set it to text saying rainbow.

Second. Just swap over the if statement for the touchpoint api into your test code, rather than your api.

I have actually did that before but that didn't worked but this

if colorActive == rainbow then
does.
And second which if statment do you mean?

Here's a quick example of http.get (using touchpoint)


local h = http.get( "http://pastebin.com/raw.php?i=pFHeia96" ) --#get the raw paste
if h then
  local f = fs.open( "touchpoint", "w" ) --#open the 'touchpoint' file in write mode
  f.write( h.readAll() ) --#write the contents of the raw paste to the file
  f.close() --#close the file handle
  h.close() --#close the web handle
end
Thanks for the code i have put it in my code.

I will explain what i tested tomorrow don't have enough time now. :)/>
Edited on 24 April 2015 - 05:36 PM
Cing #8
Posted 24 April 2015 - 01:59 PM
I have tested my programs a bit more and here are the new versions:
API: http://pastebin.com/SG2dU6eU
Test program: http://pastebin.com/Ey8jWUJA

The API works in the way that it creats a Numberpad.
But after the 2 sec. sleep it draws the other button and removes the numberpad.

What i really want is that numberpad function just adds the button in the same way when you have all the "t:add"s in your program.
Cing #9
Posted 24 April 2015 - 06:18 PM
I have another question:
How do you put a image in "a post"?

Never mind already got it figured out.
Edited on 24 April 2015 - 05:40 PM
Lyqyd #10
Posted 24 April 2015 - 06:33 PM
You've localized the touchpoint page instance that your API is using. You should not make it local, and then use setNumberPad.t:add(…) in your script, getting rid of the page being declared in the script entirely.
Cing #11
Posted 24 April 2015 - 06:57 PM
I don't understand what you mean.
how could i use setNumberPad.t:add(..)?
Edited on 24 April 2015 - 05:01 PM
Lyqyd #12
Posted 24 April 2015 - 07:41 PM
In the API, where you have `local t = touchpoint.new`, get rid of the local keyword. In the script, get rid of the declaration of t entirely, and change all the stuff that uses t to use setNumberPad.t instead.
Cing #13
Posted 24 April 2015 - 09:01 PM
Thanks i got it working but i get a error when pressing a button using setNumberPad.t:run() i Get a error
Lyqyd #14
Posted 24 April 2015 - 10:07 PM
Please post the updated code, the full text of the error, and describe which button causes the issue.
Cing #15
Posted 24 April 2015 - 10:37 PM
I have updated the pastebin and the error is:
touchpoint:104: attempt to call nil
I get this error when i click on the buttons of the numberpad even the one with a function.
But the "derp" button works
Edited on 24 April 2015 - 08:38 PM
Bomb Bloke #16
Posted 24 April 2015 - 11:29 PM
This has to do with environments. When an API is loaded, it's placed into its own environment, one without access to the regular user environment that your regular scripts run in. (Shell and multishell are also loaded into the "regular" environment.) Both APIs and user scripts have access to _G, but for the purposes of ComputerCraft, _G isn't the environment our code executes in.

What this means is that if you define a global such as "Six" in your script, then that global will reside in the user environment; when your API goes to reference "Six", it'll look for it in the API's own unique environment. It won't find it there.

There are a few ways around this; to me, the most elegant one would be to move your button function definitions into your API.