Jump to content




Touchpoint API


277 replies to this topic

#241 Lupus590

  • Members
  • 1,998 posts
  • LocationUK

Posted 09 November 2016 - 10:25 PM

View PostAndrothia, on 09 November 2016 - 09:19 PM, said:

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

I would have each page as a function, here's an example

--# using comments as I'm too sleepy to actually look up the API functions I should be calling
local function exampleMenu()
  --# create new terminal object with the window API (or some other API)
  --# redirect the terminal to this new window (remember to store the returned value, this was the old terminal object)
  --# create a new touchpoint instance, this will 'bind' itself to this terminal object.
  --# draw buttons

  local exit = false
  while not exit do --# event loop
	local event = {os.pullEvent()}
	--# process event, handle buttons, ect.
  
	--# eventually the back button will be pressed, which only sets exit to true, ending the loop and returning the function
  end
  --# cleanup bit, restore the current terminal to the one which was stored at the start of this function
end


Edited by Lupus590, 09 November 2016 - 10:27 PM.


#242 standal

  • New Members
  • 1 posts

Posted 13 January 2017 - 01:16 PM

hello, I would like to ask for your help I done something wrong and I can not find where to but does not display the contents of the chest
I thanked him for his help when someone tuna
http://raw.githubuse...ter/Spawner.lua

#243 Lupus590

  • Members
  • 1,998 posts
  • LocationUK

Posted 13 January 2017 - 07:22 PM

View Poststandal, on 13 January 2017 - 01:16 PM, said:

hello, I would like to ask for your help I done something wrong and I can not find where to but does not display the contents of the chest
I thanked him for his help when someone tuna
http://raw.githubuse...ter/Spawner.lua

Your messy indenting at the end is a clue, you're missing an end for your reloadMobs function.

Edited by Lupus590, 13 January 2017 - 07:22 PM.


#244 tycoonlover1359

  • Members
  • 9 posts

Posted 29 March 2017 - 03:06 AM

If I make my program handle more than one event, but touchpoint is one of the APIs waiting for an event, what will happen? For instance, what would happen if this is my code:
event, message, p1 =  t:handleEvents(os.pullEvent())
If event == "button_click" then
  print(p1)
elseif event == "modem_message" then
  print(message)
end
Would anything get messed up? If so, what would I do so that my program can handle both button inputs and modem messages?

#245 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,455 posts

Posted 29 March 2017 - 03:16 AM

You'd want to use less event-specific names for the event parameter variables. I usually just chuck them all in a table and index out what I need, but if you prefer the list:

local event, param1, param2, param3, param4, param5 = t:handleEvents(os.pullEvent())
if event == "button_click" then
  print(param1) --# the name of the button clicked
elseif event == "modem_message" then
  print(param4) --# the message that arrived
end

But you're definitely on the right track! The ability to handle multiple types of events is exactly what the handleEvents function in Touchpoint was built for.

#246 tycoonlover1359

  • Members
  • 9 posts

Posted 29 March 2017 - 03:32 AM

View PostLyqyd, on 29 March 2017 - 03:16 AM, said:

You'd want to use less event-specific names for the event parameter variables. I usually just chuck them all in a table and index out what I need, but if you prefer the list:
local event, param1, param2, param3, param4, param5 = t:handleEvents(os.pullEvent())
if event == "button_click" then
print(param1) --# the name of the button clicked
elseif event == "modem_message" then
print(param4) --# the message that arrived
end
But you're definitely on the right track! The ability to handle multiple types of events is exactly what the handleEvents function in Touchpoint was built for.

Ok, now that I'm on the right track, how would I do something like what's in this video: https://youtu.be/KX9JSjC41uI . The API used here is DW20's Button API, but I'm since learning to use Touchpoint; Touchpoint seems much easier to use. Essentially, when I want the code to check for multiple events, I'd use
 t:handleEvents(os.pullEvent())
but how would I check for 3 or 4 inputs; I'm unsure of which loop to use, if any. I want to be able to check for four inputs (button presses) and compare those to a password I set before, but I also want to ensure that if I send a certain command to the computer (for instance, lock) then the computer will clear the screen, print "locked" and not allow monitor input, but also do the inverse and have it so when I send a command to the computer (ex., unlock) then the computer will return to showing the keypad and allow monitor input, just as before. I know I could just check for this input again and again, setting the input to a variable then at the end comparing the variable(s) to my set password, but I'd want to know if there is a more efficient way of doing this.

EDIT: So this is what I currently have for my door. I've left out most of it, leaving only that part I actually need to use.
While true do
  Local event, param1, param2, param3, param 4, param5 = t:handleEvents(os.pullEvent())
  If event == "button_click" then 
    Local 1 = param1 --# This can be changed to store inputs as a table, if it's more efficient or 'better'
    	--# I don't know what to put here
In the area I've marked where I don't know what to put, what I want to happen is after I click a number button, the computer will save the input in a variable. I then want it to go back to the beginning and wait for an input again, with that input being stored in another variable. Is there a way I could do this? If so, how? Also, is storing my inputs as a table a good idea? It seems like it may make it easier to compare the data in the input table to the data in the correct password table. If this is a good idea, how would I do that?

Edited by tycoonlover1359, 29 March 2017 - 06:08 AM.


#247 tycoonlover1359

  • Members
  • 9 posts

Posted 31 March 2017 - 01:31 AM

How would I make it so that when I toggle the button, it does something different each time? What I want to happen is that, if I click the button, it would turn green, sending a message via the RedNet/Modem APIs, but if I click the button again, turning it red, it would send a different message via the RedNet/Modem APIs.

#248 Bomb Bloke

    Hobbyist Coder

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

Posted 01 April 2017 - 09:30 AM

Define an upvalue for the button's function, and check it each time that function is called. Eg:

local buttonStatus = false

local function buttonFunction()
  if buttonStatus then
    -- Button is set, toggle it off and send one message.

  else
    -- Button is not set, toggle it on and send the other message.

  end

  buttonStatus = not buttonStatus  -- Invert the boolean.
end


#249 brainytwoo

  • Members
  • 15 posts

Posted 05 April 2017 - 12:26 AM

Just a quick question here.

Is there a way to change the text color on the buttons?

Thanks in advance!

#250 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,455 posts

Posted 05 April 2017 - 02:27 AM

Yes. The first post doesn't mention it, but there are two additional color arguments after the background color arguments. They will set the colors for the text of the button in the inactive and active state, and are in the same order as the background color arguments.

#251 brainytwoo

  • Members
  • 15 posts

Posted 05 April 2017 - 04:14 AM

Sweet!

Thanks man.

#252 brainytwoo

  • Members
  • 15 posts

Posted 06 April 2017 - 02:52 AM

Could I maybe get some assistance with my code?

I am using your button API and I got almost everything working perfect... almost.

When I Spam click on random buttons, and I click on a button for a turbine that is off, it turns the turbine on.

I cant find if its a pattern or truly random but it is only supposed to turn on the turbine if you hit the on button.


Here is the code: https://pastebin.com/yQQC8jj9

Thanks in advance even if you couldn't find anything.

Never mind, I found the issue.
I was using a function to toggle all the buttons and if the button was set to "OFF" and the turbine was actually on, then it would tell the function to toggle the on/off button.
Only problem with that is, whenever the on/off button is toggled, it turns on/off the turbine that is selected.

Edited by brainytwoo, 06 April 2017 - 11:48 AM.


#253 HamishWHC

  • Members
  • 7 posts

Posted 13 April 2017 - 12:44 AM

Hey Lyqyd,

Is it possible to have a function (of a button) have arguements. i.e. loginPage:add("Hello", display(mainMenu) , 21, 9, 30 ,11) to display a new page rather than having to make a switching function for every page.

If this is not doable currently can you make it so?

Thanks.

#254 Bomb Bloke

    Hobbyist Coder

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

Posted 13 April 2017 - 01:28 AM

loginPage:add("Hello", function() display(mainMenu) end, etc...


#255 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,455 posts

Posted 13 April 2017 - 01:45 AM

The easiest way to do that is to just make an anonymous function to call the desired function with its argument. Like so:

loginPage:add("Hello", function() return display(mainMenu) end, 21, 9, 30 ,11)

Edit: Yeah, I left this page open for a while, so Bomb Bloke jumped in and answered before I could!

#256 HamishWHC

  • Members
  • 7 posts

Posted 13 April 2017 - 02:10 AM

How do I put images in it with paintutils or another way if needed?

#257 brainytwoo

  • Members
  • 15 posts

Posted 24 April 2017 - 06:59 PM

Is there a way to have more then 1 button with the same name on the same page at the same time?

for instance:

|-100| |-10| |-5| |num 1| |+5| |+10| |+100|

|-100| |-10| |-5| |num 2| |+5| |+10| |+100|

#258 brainytwoo

  • Members
  • 15 posts

Posted 24 April 2017 - 07:25 PM

I just realized that you don't need to have touchpoint handle the events, do you?

if not, I could simply add an if statement checking weather the touch is on the top or bottom of the screen and toggle the button accordingly.

If there is someone that has done anything like this before and has a better solution, please let me know.

Thanks and have a great day.

#259 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,455 posts

Posted 24 April 2017 - 08:24 PM

View PostHamishWHC, on 13 April 2017 - 02:10 AM, said:

How do I put images in it with paintutils or another way if needed?

You'd need to replace the draw function of your touchpoint instance to draw the image and then draw the buttons.

View Postbrainytwoo, on 24 April 2017 - 06:59 PM, said:

Is there a way to have more then 1 button with the same name on the same page at the same time?
for instance:
|-100| |-10| |-5| |num 1| |+5| |+10| |+100|
|-100| |-10| |-5| |num 2| |+5| |+10| |+100|

Yes, you could provide a label table that gives each button a unique name, but the same visible content.

View Postbrainytwoo, on 24 April 2017 - 07:25 PM, said:

I just realized that you don't need to have touchpoint handle the events, do you?
if not, I could simply add an if statement checking weather the touch is on the top or bottom of the screen and toggle the button accordingly.
If there is someone that has done anything like this before and has a better solution, please let me know.
Thanks and have a great day.

Any click events that don't match a button are allowed to fall through the handleEvents call unchanged, so you could indeed watch for clicks happening on the top or bottom rows of the screen, provided you don't have any buttons there.

#260 brainytwoo

  • Members
  • 15 posts

Posted 24 April 2017 - 09:36 PM

Ok. I have tried your table method that you mentioned, I believe it is the one that you have in post #1?

Anyway, I would like the buttons to be 1 pixel tall, but when I remove the extra lines, it puts a bunch of "nil"'s on the screen.

Is there a way around this?

other then this, it works perfect, thank you.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users