Jump to content
  • Advertisement
Sign in to follow this  
Colin333

More basic code trouble...

This topic is 3776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I'm trying to experiment with functions and I've not been able to get it working.
;;;;;;;;;;;;;;;;
;Log in Program;
;;;;;;;;;;;;;;;;

username$ = Input$( "To Log in Type your username:")
password = Input( "Please type in your password:")

;Function performed if access is granted		
Function yes()

Print "Welcome back " + username$ + "!" 
	Delay 2000

Print "Hit any key to continue."
	WaitKey
		End Function

;function performed if access is denied
Function no()

Print "Your username or password is incorrect."

	WaitMouse
		End Function

If username$ = "Colin" And password = 11032 Then
	yes()
Else
no()	
End If

End 



So the trouble I'm having is when I input the correct username & password all it says is "Welcome back !" completely ignoring the username$ variable, can someone help me out? *Please note this is written in the BASIC language.

Share this post


Link to post
Share on other sites
Advertisement
As far as i can see, you have defined a function called Yes, but it isnt called, so i don't know why your getting a message printed.

One solution would be to declare the username$ and password as global variables, so the yes function gets access to them.

global username$
global password

username$ = Input$( "To Log in Type your username:")
password = Input( "Please type in your password:")

; call the function
yes()
end ; end programme


Function yes()

Print "Welcome back " + username$ + "!"
Delay 2000

Print "Hit any key to continue."
WaitKey

End Function




But a better solution is to pass variables to the function itself.

username$ = Input$( "To Log in Type your username:")
password = Input( "Please type in your password:")

; call the function whilst passing the vars to it you want.
yes(username$,password)
end


Function yes(var$,var)

Print "Welcome back " + var$ + "!"
Delay 2000

Print "password = " + var
Delay 2000

Print "Hit any key to continue."
WaitKey

End Function


Hope thats clearer.

KJM

Share this post


Link to post
Share on other sites
Oh yeah thanks a bunch. I knew I was missing something, I've just started up programming so I'm pretty bad at this (as I'm sure you can tell). Thanks for your patience and help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!