Jump to content




Buttons from button API not appearing on monitor

api

7 replies to this topic

#1 Kiedamon

  • Members
  • 3 posts

Posted 22 July 2016 - 11:16 PM

I found Direwolf20's video on Button API and using the pastebin link, managed to copy the API into my program. As far as I can see, I got everything right, and using the LuaAPI editor program for the computers, it doesn't say there's any errors, but my buttons simply refuse to show up. I thought it might be a color problem and they're just black like the background but pressing where the buttons should be has no effect. This is the link for my programming http://pastebin.com/Q6G58LS1

#2 Emma

  • Members
  • 216 posts
  • Locationtmpim

Posted 23 July 2016 - 03:52 AM

The very first line of your program is
`mon = peripheral.wrap("monitor_0")
There is a ` before mon, which changes the name of the variable. Remove that and it should work.

#3 The_Cat

  • Members
  • 119 posts

Posted 23 July 2016 - 07:09 AM

Would recommend: http://www.computerc...touchpoint-api/
A much more versatile button API.

#4 Kiedamon

  • Members
  • 3 posts

Posted 24 July 2016 - 02:24 PM

sorry Incinerate. I typed that in just before I pasted it to pastebin. I tried to run it again and it LuaIDE gave me an error saying unexpected symbol. I already know that was there and the buttons still didn't appear when I removed it. and I'll take a look The_Cat

The_Cat, while touchpoint API is great, it seems to be giving me problems, as in totally overwriting my screen and stopping any of my progress bars or titles from appearing. also, due to the limitation of A, the room I'm working in, and B, you can only have a monitor 8 across, I am unable to fit my progress bars with a still respectable length and the buttons due to them having a label border that I cant remove. for example, the button now labeled A+10 only appears as A+ because of a 1 one character border on each side. Other than those two problems, all I have to do is play around with the button functions a bit so the program stops crashing when I hit one of the +/- buttons that would put the control rod insertion >100/<0. So, if anyone could help with the label border and bar erasing problems, as I am not the most program savvy person and I would rather not play with Lyqyd's touchpoint API in fear of breaking something, that would be great.

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 July 2016 - 06:37 PM

The two usual options would be to move the touchpoint instance's draw call to the top of your drawing function, or to copy the draw function out of the API, remove the clear call, and override your instance's draw function with the modified one.

#6 The_Cat

  • Members
  • 119 posts

Posted 24 July 2016 - 09:18 PM

As for the original code, I can't see any errors with it. To be sure i'd double check the name of the monitor, maybe even put to next to the computer? Does the text appear that you are writing?

#7 Kiedamon

  • Members
  • 3 posts

Posted 26 July 2016 - 11:57 AM

the monitor certainly works The_Cat. I'm just having problems making it display the progress bars and the buttons. Lyqyd, as the draw function has a built in clear monitor I assume I could just replace the clear at the top of my while loop and it should draw the buttons first then the progress bars over that. Thinking ahead, the only thing I'm worried about is that if the touchpoint API waits for an input like read(), it wouldn't update my reactor info on the fly such as fuel levels and stored energy, though I'm unsure exactly of how your API works Lyqyd.

Edit: also Lyqyd, as it is your API, if there is some easy modification I can make to the touchpoint API program that would remove the label buffers that would be great to know as I would prefer to not shrink my progress bar any further.

Edit 2: upon attempting to move the touchpoint API draw function to the top of my draw functions to be sure that it didnt work, as I had attempted that before, I noticed Lua API program editor was saying that my centerText function has "function arguments expected" I am unsure if it's just me being totally oblivious or if there's a far more subtle change that's happened that would cause this to happen. Because of this and changes I've made to the program since I last posted it I have decided to update the pastebin link here.
http://pastebin.com/dNKeNder

Edited by Kiedamon, 26 July 2016 - 01:55 PM.


#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 26 July 2016 - 05:38 PM

Touchpoint will only do what you tell it to. The most common way of using it is to use its handleEvents call, which transforms monitor_touch events on its buttons into button_click events. You can fairly easily integrate this into your existing event handling loop alongside the timer events you're using to update the other things you're displaying.

You can custom specify the exact contents of the button labels by renaming then with a table of strings rather than a textual label. This will allow you to override the margins that Touchpoint typically enforces. Simply have a string as long as the button is wide for each row of the button's height. A three-high, four-wide button named "nums" could be labeled this way like this:

t:rename("nums", {"1234", "5678", "90ab", label = "nums"})

You can also declare the buttons initially with that table structure in place of the name. Just don't forget to include a label in the table!

Looks like you forgot the parentheses on the draw call, it should be t:draw().

Also, I see that you're sleeping in your main loop. That's not going to work for what you're trying to do. You're going to want to separate out your drawing routine from the information gathering. You'll want to create a redraw function that you call any time you get a button click or you've fetched updated information from the reactor. You can also get away with fetching information much less often. Once per second should be more than enough.

You'll want to create an event handling loop that will handle timer events as well as button events. The timer event handling would fetch a new set of information from the reactor, then call your redraw function and start a new timer. The button click event handling would react to the button being pressed (since you have functions for each button, this is as easy as t.buttonList[p1].func(), assuming p1 is the first argument after the event name for the returned event data).





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users