Noneatme Posted August 1, 2012 Share Posted August 1, 2012 Hello there, I have a very big problem with my calculator. Because I do not understand how to user string.find or string.sub! Here is a screenshot: The buttons work and the string above the keypad too, but I dont know what I should made with the "="... Here is my code: -- GUI BUTTONS ABOVE HERE local cal_anzeige = "0" addEventHandler("onClientGUIClick", button["cal:num+"], function() local l = #cal_anzeige if(l > 29) or (l < 1) then return end local last = string.sub(cal_anzeige, #cal_anzeige, #cal_anzeige) if(last == "+") or (last == "-") or (last == "*") or (last == "/") or (last == ".") then return end cal_anzeige = cal_anzeige.."+" end, false) addEventHandler("onClientGUIClick", button["cal:num-"], function() local l = #cal_anzeige if(l > 29) or (l < 1) then return end local last = string.sub(cal_anzeige, #cal_anzeige, #cal_anzeige) outputChatBox(last) if(last == "+") or (last == "-") or (last == "*") or (last == "/") or (last == ".") then return end cal_anzeige = cal_anzeige.."-" end, false) addEventHandler("onClientGUIClick", button["cal:num*"], function() local l = #cal_anzeige if(l > 29) or (l < 1) then return end local last = string.sub(cal_anzeige, #cal_anzeige, #cal_anzeige) if(last == "+") or (last == "-") or (last == "*") or (last == "/") or (last == ".") then return end cal_anzeige = cal_anzeige.."*" end, false) addEventHandler("onClientGUIClick", button["cal:num/"], function() local l = #cal_anzeige if(l > 29) or (l < 1) then return end local last = string.sub(cal_anzeige, #cal_anzeige, #cal_anzeige) if(last == "+") or (last == "-") or (last == "*") or (last == "/") or (last == ".") then return end cal_anzeige = cal_anzeige.."/" end, false) addEventHandler("onClientGUIClick", button["cal:num0"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."0" end, false) addEventHandler("onClientGUIClick", button["cal:num1"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."1" end, false) addEventHandler("onClientGUIClick", button["cal:num2"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."2" end, false) addEventHandler("onClientGUIClick", button["cal:num3"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."3" end, false) addEventHandler("onClientGUIClick", button["cal:num4"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."4" end, false) addEventHandler("onClientGUIClick", button["cal:num5"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."5" end, false) addEventHandler("onClientGUIClick", button["cal:num6"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."6" end, false) addEventHandler("onClientGUIClick", button["cal:num7"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."7" end, false) addEventHandler("onClientGUIClick", button["cal:num8"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."8" end, false) addEventHandler("onClientGUIClick", button["cal:num9"], function() local l = #cal_anzeige if(l > 29) then return end cal_anzeige = cal_anzeige.."9" end, false) addEventHandler("onClientGUIClick", button["cal:num="], function() local wert = cal_anzeige -- plus -- end, false) addEventHandler("onClientGUIClick", button["cal:numdel"], function() cal_anzeige = string.sub(cal_anzeige, 1, #cal_anzeige-1) end, false) Thank you for help! -None Link to comment
_Dark_ Posted August 1, 2012 Share Posted August 1, 2012 Sorry for offtopic, but: You want make Android in MTA? Link to comment
Noneatme Posted August 1, 2012 Author Share Posted August 1, 2012 (edited) No its a SMARTPHONE with functions like web browser and my own houses for example.... /edit btw.: Edited August 1, 2012 by Guest Link to comment
_Dark_ Posted August 1, 2012 Share Posted August 1, 2012 No its a SMARTPHONE with functions like web browser and my own houses for example.... I know, this is Galaxy Ace with Android 2.3 Link to comment
Noneatme Posted August 1, 2012 Author Share Posted August 1, 2012 No its a galaxy sII i9100 Link to comment
_Dark_ Posted August 1, 2012 Share Posted August 1, 2012 Oh, I always confuse them By subject: local str = "2152+242/231" local result = loadstring("return "..str)() -- this is your math result Link to comment
_Dark_ Posted August 1, 2012 Share Posted August 1, 2012 Wow, I looked screenshots, awesome, very nice! Link to comment
Noneatme Posted August 1, 2012 Author Share Posted August 1, 2012 Oh, I always confuse them By subject: local str = "2152+242/231" local result = loadstring("return "..str)() -- this is your math result I love you No homo, but thank you :D -None Link to comment
_Dark_ Posted August 1, 2012 Share Posted August 1, 2012 I love you No homo, but thank you :D You're welcome Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now