Jump to content




Button/Rectangle Creating function doesn't work correctly


  • You cannot reply to this topic
6 replies to this topic

#1 n1ghtk1ng

  • Members
  • 58 posts

Posted 08 January 2013 - 06:32 PM

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!

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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.

Edited by TheOriginalBIT (OnHoliday), 08 January 2013 - 07:08 PM.


#3 n1ghtk1ng

  • Members
  • 58 posts

Posted 09 January 2013 - 01:31 AM

Whoops...

#4 n1ghtk1ng

  • Members
  • 58 posts

Posted 09 January 2013 - 01:35 AM

View PostTheOriginalBIT, 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.


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 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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
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. :) I have seen others actually use the _ though, but thats bad naming convention.

#6 n1ghtk1ng

  • Members
  • 58 posts

Posted 09 January 2013 - 01:47 AM

View PostTheOriginalBIT, 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
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. :) I have seen others actually use the _ though, but thats bad naming convention.
37:Attempt to get length of nil ; Where is the table "info" made?(didn't know how to describe it)

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 January 2013 - 01:51 AM

sorry that was bad communication on my part do one of the following

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