I made a function that would spawn a button, given the length, height, coordinates(x & y), and so on.
I've been doing this for a few hours, and I still have at least, two bugs:
-If the y-coordinate is greater than or equal to the height, then the whole screen gets filled with the chosen
-If all of the variables (length, width, x-coord) except the y-coord are equal, then it only prints one line, and goes on forever, until it returns "too long without yielding" (I know this is because I don't have a sleep(?)
Please test this out and help me with the bugs. Although this isn't that big of a project nor alot of code, I've never really had to identify bugs and fix them, nor think this hard about (a) project/code
link:http://pastebin.com/GmhH4ABX
Thanks!
Button/Rectangle Creating function doesn't work correctly
Started by n1ghtk1ng, Jan 08 2013 06:32 PM
6 replies to this topic
#1
Posted 08 January 2013 - 06:32 PM
#2
Posted 08 January 2013 - 06:37 PM
I would suggest that the easiest thing would be to add in a bunch of validation and return an error if something is wrong.
Off topic side note: I think that for the click functions and such it may be easier now if you implement it that the program 'registers' a button that is then stored in a table. which then can be used by draw and clicked
EDIT: Here is a small example of what I mean ( this was typed in pastebin, so sorry if there are some typos) :
http://pastebin.com/JMeTqWNc
If you need me to explain anything here, just ask.
Off topic side note: I think that for the click functions and such it may be easier now if you implement it that the program 'registers' a button that is then stored in a table. which then can be used by draw and clicked
EDIT: Here is a small example of what I mean ( this was typed in pastebin, so sorry if there are some typos) :
http://pastebin.com/JMeTqWNc
If you need me to explain anything here, just ask.
Edited by TheOriginalBIT (OnHoliday), 08 January 2013 - 07:08 PM.
#3
Posted 09 January 2013 - 01:31 AM
Whoops...
#4
Posted 09 January 2013 - 01:35 AM
TheOriginalBIT, on 08 January 2013 - 06:37 PM, said:
I would suggest that the easiest thing would be to add in a bunch of validation and return an error if something is wrong.
Off topic side note: I think that for the click functions and such it may be easier now if you implement it that the program 'registers' a button that is then stored in a table. which then can be used by draw and clicked
EDIT: Here is a small example of what I mean ( this was typed in pastebin, so sorry if there are some typos) :
http://pastebin.com/JMeTqWNc
If you need me to explain anything here, just ask.
Off topic side note: I think that for the click functions and such it may be easier now if you implement it that the program 'registers' a button that is then stored in a table. which then can be used by draw and clicked
EDIT: Here is a small example of what I mean ( this was typed in pastebin, so sorry if there are some typos) :
http://pastebin.com/JMeTqWNc
If you need me to explain anything here, just ask.
A have a few questions,
What does "unpack", "math.floor", "string.rep", and "_" do?
Also, it returns an error; 38:Attempt to get length of number (meaning #info), also you were missing an "=" on line 26( if height == math.floor(v[2]/2) )
Thanks for the help!
#5
Posted 09 January 2013 - 01:42 AM
Oh yes oops at least it was only 2, quick typing and pastebin don't make for good code... You can remove the unpack now. that was one of the last changes I made, its not needed. unpack actually puts all the values in a table into their own variable. so we would do say this
removing the unpack should remove the error on line 38
math.floor rounds a number down. so say I give it 7.3 it will make it 7 or if i give it 7.8 it will still give me 7. math.ceil is rounding up
as for the _ thats just a coding habit of mine. you could have any identifier for a variable there that you wish, something like k ( meaning 'key' ). I use _ for anything that I'm not actually using, just so when I read through I can quickly tell.
I have seen others actually use the _ though, but thats bad naming convention.
local x, y, z = unpack( tTable )where tTable is say { 1, 6, 13 }
removing the unpack should remove the error on line 38
math.floor rounds a number down. so say I give it 7.3 it will make it 7 or if i give it 7.8 it will still give me 7. math.ceil is rounding up
as for the _ thats just a coding habit of mine. you could have any identifier for a variable there that you wish, something like k ( meaning 'key' ). I use _ for anything that I'm not actually using, just so when I read through I can quickly tell.
#6
Posted 09 January 2013 - 01:47 AM
TheOriginalBIT, on 09 January 2013 - 01:42 AM, said:
Oh yes oops at least it was only 2, quick typing and pastebin don't make for good code... You can remove the unpack now. that was one of the last changes I made, its not needed. unpack actually puts all the values in a table into their own variable. so we would do say this
removing the unpack should remove the error on line 38
math.floor rounds a number down. so say I give it 7.3 it will make it 7 or if i give it 7.8 it will still give me 7. math.ceil is rounding up
as for the _ thats just a coding habit of mine. you could have any identifier for a variable there that you wish, something like k ( meaning 'key' ). I use _ for anything that I'm not actually using, just so when I read through I can quickly tell.
I have seen others actually use the _ though, but thats bad naming convention.
local x, y, z = unpack( tTable )where tTable is say { 1, 6, 13 }
removing the unpack should remove the error on line 38
math.floor rounds a number down. so say I give it 7.3 it will make it 7 or if i give it 7.8 it will still give me 7. math.ceil is rounding up
as for the _ thats just a coding habit of mine. you could have any identifier for a variable there that you wish, something like k ( meaning 'key' ). I use _ for anything that I'm not actually using, just so when I read through I can quickly tell.
#7
Posted 09 January 2013 - 01:51 AM
sorry that was bad communication on my part do one of the following
Change this
OR
remove this line
Change this
local info = unpack( button )to this
local info = button
OR
remove this line
local info = unpack( button )and replace all the 'info' in that function to 'button'
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











