Jump to content




Calculator input


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

#1 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

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

#2 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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

#3 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 26 February 2013 - 05:47 AM

View PostremiX, on 26 February 2013 - 05:38 AM, said:

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

#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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


#5 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 26 February 2013 - 06:46 AM

View PostremiX, on 26 February 2013 - 05:54 AM, said:

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 :)

#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

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..

#7 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users