How to run a function within a function that will run by itself
#1
Posted 18 November 2015 - 10:58 PM
#2
Posted 18 November 2015 - 11:15 PM
#4
Posted 19 November 2015 - 01:58 AM
#5
Posted 19 November 2015 - 02:05 AM
KingofGamesYami, on 19 January 2019 - 11:45 AM, said:
Edited by Twijn, 19 November 2015 - 02:05 AM.
#6
Posted 19 November 2015 - 03:10 AM
function handleEvents( ... )
local tEventData = { ... }
if (button was clicked) then
return "button_click", other_data
end
return ...
end
I've actually added a check to it to detect if it was passed event data - and if not, will call os.pullEvent itself.
A different approach would be to add a function that simply handles your buttons and require the user to run it in parallel themselves.
#7
Posted 19 November 2015 - 04:24 AM
#8
Posted 19 November 2015 - 04:55 AM
KingofGamesYami, on 19 November 2015 - 03:10 AM, said:
function handleEvents( ... )
local tEventData = { ... }
if (button was clicked) then
return "button_click", other_data
end
return ...
end
I've actually added a check to it to detect if it was passed event data - and if not, will call os.pullEvent itself.
A different approach would be to add a function that simply handles your buttons and require the user to run it in parallel themselves.
Also, for the user allowing it to run itself, that may cause a few issues.
Because it is a neverending loop, would it technically make multiple loops running at the same time that works off of the same table of buttons? Would that not cause buttons to trigger more then once?
I am also creating this for a different program I'm creating, so that would have its own loop as well. I also would prefer people to just be able to create the functions and add the buttons, it's way simpler.
#9
Posted 19 November 2015 - 04:40 PM
My API forces the user to handle everything. It just makes events telling them a button was pressed and which one. From there, the user of my API has absolute control over everything - otherwise you start to get complicated work-around solutions to using my API, which isn't a good thing.
I do not use a loop. I force the user to make their own loop, because more than 50% of programs are going to need that loop anyway.
The other way I have managed things (when I want things to be simple) is to have my program work like read(). One of the function is a function that returns when a button is clicked, and the data related to that button. I feel this way is easy to transition to for new users, as they have undoubtably used read() before (and if not, why are they using my API?).
Edited by KingofGamesYami, 19 November 2015 - 04:42 PM.
#10
Posted 19 November 2015 - 09:55 PM
KingofGamesYami, on 19 November 2015 - 04:40 PM, said:
My API forces the user to handle everything. It just makes events telling them a button was pressed and which one. From there, the user of my API has absolute control over everything - otherwise you start to get complicated work-around solutions to using my API, which isn't a good thing.
I do not use a loop. I force the user to make their own loop, because more than 50% of programs are going to need that loop anyway.
The other way I have managed things (when I want things to be simple) is to have my program work like read(). One of the function is a function that returns when a button is clicked, and the data related to that button. I feel this way is easy to transition to for new users, as they have undoubtably used read() before (and if not, why are they using my API?).
Also, why exactly would people need the loop?e
I have been over thinking everything you have said and I have not made complete sense of it, obviously.
It is not that hard to make them create their own loops... It is actually quite simple.
Sorry for being so stupid. xD
Edited by Twijn, 19 November 2015 - 10:03 PM.
#11
Posted 20 November 2015 - 12:57 AM
#12
Posted 20 November 2015 - 02:08 AM
Bomb Bloke, on 20 November 2015 - 12:57 AM, said:
Oh, yeah, sorry, I completely didn't see your post somehow! I'll go check it out.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











