This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Engineer's profile picture

Calculator input

Started by Engineer, 26 February 2013 - 04:30 AM
Engineer #1
Posted 26 February 2013 - 05:30 AM
Hello,
i
I got at this point a GUI with working buttons. I made it so that the system knows what button is pressed. Here is an screenshot with the debugging ON. I have clicked on the "add" button.

[attachment=1034:CalcDebug.png]

Now I need to display the numbers and the symbols in the top line. I have no clue how I am going to do that and thats why I came here.
Can you guys help me with that, and calculate the outcome?

Thanks,

Engineer
remiX #2
Posted 26 February 2013 - 05:38 AM
Have a variable which stores the numbers/math operations.
Everytime you click a number, it will add that number to the existing variable, same for an operation
Engineer #3
Posted 26 February 2013 - 05:47 AM
Have a variable which stores the numbers/math operations.
Everytime you click a number, it will add that number to the existing variable, same for an operation

Would you do that with a table?
Please give me an example
remiX #4
Posted 26 February 2013 - 05:54 AM
Well have a variable that is just "" in the beginning

local calc = ""

And then where ever your code is for when a number/math operation is clicked you just do
if ... then
     -- if 0 is clicked
          calc = calc .. '0'
     elseif ... then
          -- if + is clicked
          calc = calc .. '+'
     elseif ... then
          -- if = is clicked
          result = loadstring( 'return ' .. calc)()
          term.setCursorPos( positonToPrintAnswerAt )
          write( result )
     end
Engineer #5
Posted 26 February 2013 - 06:46 AM
Well have a variable that is just "" in the beginning

local calc = ""

And then where ever your code is for when a number/math operation is clicked you just do
if ... then
	 -- if 0 is clicked
		  calc = calc .. '0'
	 elseif ... then
		  -- if + is clicked
		  calc = calc .. '+'
	 elseif ... then
		  -- if = is clicked
		  result = loadstring( 'return ' .. calc)()
		  term.setCursorPos( positonToPrintAnswerAt )
		  write( result )
	 end

Can you work it out a little bit further, the dots confuse me.. :/
Thanks for the great response though :)/>
remiX #6
Posted 26 February 2013 - 08:59 AM
Where you have your if function in the main loop with the os.pullEvent with each if checking if the button was clicked at 0 or 1 or 3 or 9 or + or * or / etc
the … will be the conditions to check where they were clicked. Unless you're using a table.

You haven't shown us any code to work with so yeah..
Engineer #7
Posted 26 February 2013 - 10:03 AM
My code:
http://pastebin.com/EN8Y2ChZ

And yes, that I have put no code that is my fault.