Jump to content




Touchpoint API


277 replies to this topic

#221 HamishWHC

  • Members
  • 7 posts

Posted 24 July 2016 - 04:12 AM

Hi Lyqyd,

I have a problem I am trying to run a program that opens a door when I input the correct code and it isn't working.

Error Code:

touchpoint:13: vm error:
java.lang.NegativeArraySizeException

The code I wrote is this: (Not great I know but it worked until this bug.)
Spoiler

I repeat: this code WORKED (Yesterday). But is not working now and is giving this error.

Thanks!

#222 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 July 2016 - 06:56 AM

All of your button declarations need to include something where the button function argument goes (nil is fine). Right now, you first coordinate argument is in the function argument spot. Also, your digit entry event handling has some issues with the two entries for digit eight.

#223 HamishWHC

  • Members
  • 7 posts

Posted 24 July 2016 - 08:52 AM

Oh. So I was just stupid. Ok. I need to remember that. Thanks Lyqyd. Though I will probably be back as this is an awesome api that I will continue to use.

A suggestion: Ability to set button state rather than toggle. I want to be able to set a button as on rather than toggling. Like with rs.setOutput("side", true or false) Also the ability to detect the state of a button like rs.getOutput("side").

#224 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 July 2016 - 06:28 PM

You can do that by directly manipulating the touchpoint instance that the buttons are in. For instance, button "8"s active state could be checked like this:

if t.buttonList["8"].active then

You can also assign a true or false value to the active field of a button and then re-draw the touchpoint instance. Here's a function that would do that:

function setActivity(instance, name, active)
  instance.buttonList[name].active = active
  instance:draw()
end


#225 HamishWHC

  • Members
  • 7 posts

Posted 17 September 2016 - 12:00 AM

I see. Thanks. BUT. I have another question. This one is more complex (I think?) and I have no clue what I have done wrong. I am writing a program that controls my space center and am trying to run it. It gives the error:

.temp:100: attempt to index ? (a function value)

This error is given by this code:

Spoiler

Line 100 is marked with a comment.

The only thing I can think of is that login() is not defined properly but I can not see what the problem is.

Help would be great.

-HamishWHC

P.S. Not all the coordinates have been defined yet. They are just values from copy pasting from your post up the top.

EDIT: Spoiler tags.

Edited by HamishWHC, 17 September 2016 - 12:01 AM.


#226 Bomb Bloke

    Hobbyist Coder

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

Posted 17 September 2016 - 12:29 AM

When you "attempt to index" something, it means you're treating the value as a table and you're trying to get an element from within that table. You're doing this when you refer to "login:add" - this implies "login" points to the table and "add" is the element within that table.

Catch is "login" isn't a table pointer, it's a function pointer. Although you initially assigned it a table pointer early in the script:

local login = touchpoint.new("top")

... you soon replaced that with a function pointer:

function login()

You'll want to use two different variables to track the two different pointers.

#227 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 17 September 2016 - 01:43 AM

Well, you can't have one variable hold two different things. You define the login variable as a touchpoint instance, but then replace it with a function later on, and then try to call the touchpoint instance's add method, but the login variable no longer has a touchpoint instance in it.

Once you get the variable name issue sorted out, you'll want to remove the parentheses from the names of the functions you're assigning to the buttons.

Edit: Looks like I had this thread opened too long and Bomb Bloke got a reply in there first!

#228 HamishWHC

  • Members
  • 7 posts

Posted 17 September 2016 - 05:02 AM

Ok, I changed the "login" table to "loginpage" and I get the same error.

#229 Bomb Bloke

    Hobbyist Coder

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

Posted 17 September 2016 - 08:13 AM

Show us the revised code (I suggest using pastebin), and ensure the error is character-for-character the same - any changes are relevant.

#230 giantawesomemeep

  • Members
  • 9 posts

Posted 20 October 2016 - 04:14 AM

Im pretty new to touchpoint could someone tell me what im doing wrong or missing?

--# load the touchpoint API
os.loadAPI("touchpoint")
--# intialize a new button set on the top monitor
local t = touchpoint.new("left")
function Gate()
	    t:flash("Gate")
	    rednet.broadcast("gate")
end
function red()
	    t:flash("red")
	    rednet.broadcast("d1")
end
function yellow()
	    t:flash("yellow")
	    rednet.broadcast("d2")
end
function blue()
	    t:flash("blue")
	    rednet.broadcast("d3")
end
function king()
	    t:flash("king")
end
--# add two buttons
t:add("Gate", Gate, 1, 1, 18, 4, colors.green, colors.orange)
t:add("Door Red", red, 1, 5, 18, 8, colors.red, colors.orange)
t:add("Door Yellow", yellow, 1, 9, 18, 12, colors.yellow, colors.orange)
t:add("Door Blue", blue, 1, 13, 18, 16, colors.blue, colors.orange)
t:add("King's Arena", king, 1, 17, 18, 19, colors.purple, colors.purple)
--# draw the buttons
t:draw()


#231 Bomb Bloke

    Hobbyist Coder

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

Posted 20 October 2016 - 05:20 AM

You forgot to mention what your problem is, but from a glance at your code, I'd say it'd be helpful if you opened a rednet side and then, at the bottom, called t:run().

#232 Androthia

  • Members
  • 17 posts

Posted 06 November 2016 - 06:29 PM

Ok, so I've been straining my brain for 2 days trying to figure out why this code isn't working. I want to be able to click on one of the buttons, and open up a new program.

This is program is named "GUI"

Spoiler

Any help would be appreciated!

Edited by Androthia, 06 November 2016 - 06:30 PM.


#233 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 06 November 2016 - 08:04 PM

The button isn't set to active unless you set it that way, usually through the toggleButton method. Instead of checking the active property, why not simply check which button was pressed?

while true do
  t:draw()
  local event, p1 = t:handleEvents(os.pullEvent())
  if event == "button_click" then
    if p1 == "FARM_MAP" then
      shell.run("FarmMap")
    end
  end
end

I also swapped t.run for shell.run, so it will run the other program.

#234 Androthia

  • Members
  • 17 posts

Posted 06 November 2016 - 08:22 PM

That is fantastic! Thank you very much. I haven't seen much documentation on touchpoint so I wasn't exactly sure. I thought that you had to tell the script that IF the button within the buttonList was active, then it would run the function...but I see how it operates now. Seems that you made touchpoint much easier than what I thought.

Do you plan to break down touchpoint at any time to lamens terms for us dummies still learning? :P

#235 Androthia

  • Members
  • 17 posts

Posted 06 November 2016 - 08:40 PM

Ok, I may be a dummy here....but why is it that in order to quit and go back to shell....I have to terminate multiple instances instead of it just exiting out of the gui? Do I have to specify in the code to terminate current program before switching to a different program?

Spoiler


#236 Bomb Bloke

    Hobbyist Coder

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

Posted 07 November 2016 - 09:57 AM

When you shell.run() a script, loosely put, what's happening is that Lua pre-compiles that script as a function and then calls that function. When it completes, the original script carries on from where it left off - same as if you'd called any other function.

What I suspect is that, when you're done with them, you're having your child scripts (FarmMap etc) attempt to re-call the menu script. You've then got an instance of the original menu waiting for eg FarmMap to complete, which is in turn waiting for the new menu instance it spawned to complete, and so on... Better to just have the child scripts return / error / hit EOF / whatever instead, allowing the original menu to carry on each time every time you want to go back to it.

Difficult to comment on that without seeing all the code involved, of course. Pastebin that if you're still stumped.

#237 Androthia

  • Members
  • 17 posts

Posted 08 November 2016 - 08:29 PM

Whoops, I suppose that would have been a good idea. Here are the scripts for both.

GUI

Spoiler

and FarmMap

Spoiler


#238 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 08 November 2016 - 10:12 PM

View PostAndrothia, on 08 November 2016 - 08:29 PM, said:

-snip-

replace os.reboot() in farmMap and GUI with return

Edited by Lupus590, 08 November 2016 - 10:13 PM.


#239 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 09 November 2016 - 01:20 AM

When Bomb Bloke said this:

View PostBomb Bloke, on 07 November 2016 - 09:57 AM, said:

What I suspect is that, when you're done with them, you're having your child scripts (FarmMap etc) attempt to re-call the menu script. You've then got an instance of the original menu waiting for eg FarmMap to complete, which is in turn waiting for the new menu instance it spawned to complete, and so on... Better to just have the child scripts return / error / hit EOF / whatever instead, allowing the original menu to carry on each time every time you want to go back to it.

He was referring to exactly what you're doing when the Main Menu button is pushed in the FarmMap program. Instead, just use the return keyword or the break keyword to exit the loop, and the gui program will resume where it left off and allow input again. Then in gui, just include a t:draw() call in the loop to make it redraw the menu.

#240 Androthia

  • Members
  • 17 posts

Posted 09 November 2016 - 09:19 PM

Ok, Lyqyd....and with Touchpoint, would there be an easier way to switch from screen to screen? If so....could you point me in the direction for a tutorial on how to do such a thing instead of calling a different program for each different gui?

Thanks





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users