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

[Solved] Cc1.56 "atm" Accounts "if Statement" Problem

Started by Goof, 31 August 2013 - 06:12 AM
Goof #1
Posted 31 August 2013 - 08:12 AM
Just to note:

THIS IS SOLVED


Hello im trying to make a program that displays the Cash of the current account etc… but i've ran into a problem… or maybe its a bug with the CC 1.56.

It seems like the if statement is still bypassing the statement when AccountMenu is false…


if accountMenu == true and loggedBalance == false and loggedSettings == false and balanceWithdraw == false or balanceDeposit == false then

I know i could've made the == true and == false different…
but i just want to know if i've made something wrong with this if statement.. because i cant see it…
Full Code of the full API- Program- etc:

Spoilerscreen.exe : http://pastebin.com/xBHV6Gd1
startup for client: http://pastebin.com/EZc4hPzY
API: http://pastebin.com/tbC5UM7t
server startup: http://pastebin.com/Ezvg9yYF


I know theres many bugs as far… but im still working on the whole project… so dont think this code is close to done

IF any has any idea of why and how then please tell me :)/>


Old Thread:

SpoilerHello.

I'm trying to make a program that splits a string up at "&pwd=" but i've looked at the Lua manual, but no such luck there…

current code:

test = string.gmatch(msg, "(%w+)&pwd=(%w+)")
print(tostring(test))
"msg" :


msg = "$usr=64a36e9c9c4d278b9d774dc234cfd0b5572c96e3e6dc6978d86781a671e20ce2&pwd=64a36e9c9c4d278b9d774dc234cfd0b5572c96e3e6dc6978d86781a671e20ce2"
---------^--------------------------------------------------------------------^^ the &pwd= has to be the "splitter", so i can return 2 variables with the $usr=........   and the &pwd=........

The output is:

function: 963d9a

If anyone are able to help me then please tell me ;)/>

Thanks in Advance
LBPHacker #2
Posted 31 August 2013 - 08:19 AM
string.gmatch returns an iterator. You need string.find:
local _, _, first, second = string.find(msg, "^(%w+)&pwd=(%w+)$")

EDIT: Added ^ and $ anchors.
Goof #3
Posted 31 August 2013 - 08:22 AM
Oh.. Thanks :-) my mind derped out… (again)
floppyjack #4
Posted 31 August 2013 - 08:25 AM
string.gmatch returns an iterator. You need string.find:
local _, _, first, second = string.find(msg, "^(%w+)&pwd=(%w+)$")

EDIT: Added ^ and $ anchors.

Just for completion:
You can use string.match instead so you don't have to throw away any variables:

local first, second = string.match(msg, "(%w+)&pwd=(%w+)")
LBPHacker #5
Posted 31 August 2013 - 08:29 AM
-snip-
Nice one. I knew about string.match but, as you can see, Mikk wasn't the only one today whose mind derped out… +1
Goof #6
Posted 31 August 2013 - 11:02 AM
Hello everyone…


I've found an issue i cannot solve just out of my mind… (im totally confused)

code is an API:


function isPermitted(name, pass)
	local failRead = fs.open(".accounts", "r")
	local failRd = failRead.readAll()
	failRead.close()
	if not string.find(failRd, "failSafe") then
		local failSafe = fs.open(".accounts", "a")
		failSafe.writeLine("failsafe")
		failSafe.close()
	end	

	local rRead = fs.open(".accounts", "r")
	local rAll = rRead.readAll()
	rRead.close()
	print(tostring(rAll))
	if string.find(rAll, "&usr="..name.."&pwd="..pass) then
		return true
	else
		return false
	end
end	


Error is in the Topic Title

If anyone want to help me, then please comment :)/>

Thanks in Advance
Bubba #7
Posted 31 August 2013 - 11:05 AM
You really should use pastebin and give use the entire code.

That being said, my guess is that you are passing in invalid parameters to the function. The only place within the function that you use concatenation is here:

if string.find(rAll, "&usr="..name.."&pwd="..pass) then

So either name or pass must be nil. Check your usage again.
Goof #8
Posted 31 August 2013 - 11:08 AM
my program : http://pastebin.com/FbWTR1VC

my API: http://pastebin.com/Xzqd4gS0

EDIT: and btw.. i dont see any nil parametres… i think i have to make a whole debug hour…. :(/>

EDIT2: Nevermind.. i figured it out:
changed

local _, _, user, pass = string.find(msg, "^(%w+)&pwd=(%w+)*")
to

local _, _, user, pass = string.find(msg, "(%w+)&pwd=(%w+)")
Bubba #9
Posted 31 August 2013 - 11:15 AM
The error probably occurs here (line 12 of the actual program):

local _, _, user, pass = string.find(msg, "^(%w+)&pwd=(%w+)$")

My guess is that the message is not correctly formed and the string.find does not return the proper values. What message is being sent to the program?

Also, please keep questions about the same program in the same thread. I've merged them, but just keep that in mind. Thanks.
Goof #10
Posted 02 September 2013 - 04:03 PM
Ehh. as you said, then i did what you wanted…

Heres a new bug for the program… Please help me, again :)/>

- Edited OP

Thanks in Advance
GopherAtl #11
Posted 03 September 2013 - 02:42 PM
"and" has higher precedence than "or," just like * has higher precedence than +.

So your long condition, "accountMenu == true and loggedBalance == false and loggedSettings == false and balanceWithdraw == false or balanceDeposit == false", the checks for accountMenu through balanceWithdraw all get reduced to a single true/false if all are true or not, and then that is or'd with balanceWithdraw, so if balanceWidthdraw is false, the condition will run, regardless of any other conditions.

Use () to group them and force the intended order of evaluation.
Goof #12
Posted 03 September 2013 - 04:09 PM
Oh… derpy derp.
my brain is so derpy stupid….

ofc i had to use parantheses… well Thanks very much for helping my brain xD

Thanks ;)/>