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
Calculator input
Started by Engineer, Feb 26 2013 05:30 AM
6 replies to this topic
#1
Posted 26 February 2013 - 05:30 AM
#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
Everytime you click a number, it will add that number to the existing variable, same for an operation
#4
Posted 26 February 2013 - 05:54 AM
Well have a variable that is just "" in the beginning
And then where ever your code is for when a number/math operation is clicked you just do
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
Posted 26 February 2013 - 06:46 AM
remiX, on 26 February 2013 - 05:54 AM, said:
Well have a variable that is just "" in the beginning
And then where ever your code is for when a number/math operation is clicked you just do
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
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..
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
Posted 26 February 2013 - 10:03 AM
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users











