Jump to content




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


11 replies to this topic

#1 Goof

  • Members
  • 751 posts

Posted 31 August 2013 - 07: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:



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:

Spoiler

Thanks in Advance

#2 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 31 August 2013 - 07:19 AM

string.gmatch returns an iterator. You need string.find:
local _, _, first, second = string.find(msg, "^(%w+)&pwd=(%w+)$")

EDIT: Added ^ and $ anchors.

#3 Goof

  • Members
  • 751 posts

Posted 31 August 2013 - 07:22 AM

Oh.. Thanks :-) my mind derped out... (again)

#4 floppyjack

  • Members
  • 18 posts

Posted 31 August 2013 - 07:25 AM

 LBPHacker, on 31 August 2013 - 07:19 AM, said:

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+)")


#5 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 31 August 2013 - 07:29 AM

 floppyjack, on 31 August 2013 - 07:25 AM, said:

-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

#6 Goof

  • Members
  • 751 posts

Posted 31 August 2013 - 10: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

#7 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 31 August 2013 - 10: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.

#8 Goof

  • Members
  • 751 posts

Posted 31 August 2013 - 10: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+)")


#9 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 31 August 2013 - 10: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.

#10 Goof

  • Members
  • 751 posts

Posted 02 September 2013 - 03: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

#11 GopherAtl

  • Members
  • 888 posts

Posted 03 September 2013 - 01: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.

#12 Goof

  • Members
  • 751 posts

Posted 03 September 2013 - 03: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 ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users