term.clear() os.loadAPI("Apis/DesignUtil") DesignUtil.setDesign("whiteLightGray") os.loadAPI("Apis/windowSystem") local backGround,topBar=DesignUtil.getDesign() local window=windowSystem.createWindow("System setup",2,2,48,16,false) local slide=0 local U = nil local P=nil; local setupTexts= { s0="Please Enter your OSOne ID, or leave fields "; s01="blank." } function registerClick(xPos,yPos) if slide==0 then if xPos >= createIDButton.x and xPos <= createIDButton.x + createIDButton.W - 1 and yPos >= createIDButton.y and yPos <= createIDButton.y + createIDButton.H then os.reboot() end end end function verifyData(Un,Pn) if not Un and not Pn then slide=1 end end while true do term.setTextColor(colors.lightGray); paintutils.drawImage(backGround,1,1) if slide==1 then end if slide==0 then term.setCursorPos(4,4) term.setTextColor(colors.gray); print(setupTexts.s0) term.setCursorPos(4,5) print(setupTexts.s01) term.setTextColor(colors.lightGray); end windowSystem.drawWindow(window) term.setBackgroundColor(colors.white) if slide==0 then --button term.setBackgroundColor(colors.gray) term.setCursorPos(38,6) print(" ") term.setCursorPos(20,6) term.setBackgroundColor(colors.white) print("OSOne ID Username: ") term.setCursorPos(38,6) term.setBackgroundColor(colors.gray) term.setTextColor(colors.lightGray); U=read() term.setBackgroundColor(colors.white) term.setTextColor(colors.gray); term.setCursorPos(20,7) print("OSOne ID Password: ") term.setBackgroundColor(colors.gray) term.setCursorPos(38,7) print(" ") term.setCursorPos(38,7) term.setTextColor(colors.lightGray); P=read("*") verifyData(U,P) term.setBackgroundColor(colors.white) end sleep(0.15) endas you can see, if tha two fields have been Entered, it is supposed to run verifyData, it doesnt, verifyData does not set slide to 1, as that would clear the screen from the text but the screen stays the same. How can I make that work?
0
Check, If Read() Results Are Nil
Started by makerimages, Sep 19 2013 08:01 AM
3 replies to this topic
#1
Posted 19 September 2013 - 08:01 AM
Here`s my code;
#2
Posted 19 September 2013 - 08:09 AM
As i understood then here's my explanation:
This code is never setting slide to 1 unless Username AND Password hasn't been entered (is nil)
Therefore slide will never be set to 1.
Deleting the "not" will make it set slide to 1 IF both Un and Pn is true.
If this wasn't the way you want it, then tell me
I hope that'd help
This code is never setting slide to 1 unless Username AND Password hasn't been entered (is nil)
function verifyData(Un, Pn) if not Un and not Pn then -- checks if Un and Pn is false or nil slide = 1 -- then sets slide to 1.. end end
Therefore slide will never be set to 1.
Deleting the "not" will make it set slide to 1 IF both Un and Pn is true.
function verifyData(Un, Pn) if Un and Pn then slide = 1 end endElse, as the title says then do:
U=read() P=read("*") if U ~= nil and P ~= nil then verifyData(U,P) end
If this wasn't the way you want it, then tell me
I hope that'd help
#3
Posted 19 September 2013 - 09:18 AM
read() never returns nil, it returns an empty string ( "" ) if nothing was entered.
#4
Posted 19 September 2013 - 09:26 AM
Well then edit to this:
as easy as it is
U=read() P=read() if U ~= "" and P ~= "" then verifyData(U,P) end
as easy as it is
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users