? Input help? (Page 2) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password

Input help?

1 2
  • #21 ✎ 192 TheV360 Third Year My account is over 3 years old Website First Day Joined on the very first day of SmileBASIC Source Website Night Person I like the quiet night and sleep late. Express Yourself Sorry, I'm super picky about code styling. Here's a slightly more efficient version of Shelly's code: INPUT "Enter Password";PASSWORD$ VARIABLE=0 IF PASSWORD$=="STRING" THEN IF VARIABLE THEN GOTO @LOOPONE ELSE GOTO @LOOPTWO ENDIF ENDIFPro tip: in SmileBASIC, there's no such thing as a boolean variable type, so
    1. TRUE = 1
    2. FALSE = 0
    3. and IF VARIABLE THEN is the same as IF VARIABLE>0 THEN
    Posted Edited by TheV360
  • #22 ✎ 24 Crazyblob Beginner Programmer I'm just starting out! I'm still trying to grasp the basics. Programming Strength Video Games I like to play video games! Hobbies Minecraft Is Awesome! I love Minecraft! Express Yourself Ohhhh, thank you! Posted
  • #23 ✎ 98 niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies Actually, IF VARIABLE THEN is the same as IF VARIABLE!=0 THEN. Any number that isn't 0 counts as true, including negative numbers. Posted
  • #24 ✎ 44 FFVDGames Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Second Year My account is over 2 years old Website Star Wars Is Awesome! I love Star Wars! Express Yourself
    Yup, thank you guys. I'm working on a text adventure type of game, so that's why I've been asking for this info.. and cuz I'm new to programming.
    ayy I'm doing that too but on and off cuz BASIC bad and slowly becoming an adult plskillme
    Posted
  • #25 ✎ 24 Crazyblob Beginner Programmer I'm just starting out! I'm still trying to grasp the basics. Programming Strength Video Games I like to play video games! Hobbies Minecraft Is Awesome! I love Minecraft! Express Yourself Yeah basics pretty old.. I guess I better start learning python Posted
  • #26 ✎ 302 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Btw if you want you can use DEF'd statements instead of GOTO because DEF is less likely to mess up somewhere and can be neater. Posted
  • #27 ✎ 24 Crazyblob Beginner Programmer I'm just starting out! I'm still trying to grasp the basics. Programming Strength Video Games I like to play video games! Hobbies Minecraft Is Awesome! I love Minecraft! Express Yourself How's it less likely to mess up? Posted
  • #28 ✎ 302 spaceturtles Video Games I like to play video games! Hobbies Avatar Block I didn't change my avatar for 30 days. Website Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Lumage showed something using an IF statement and a GOTO. Not really a big deal I think. Posted
  • #29 ✎ 83 seggiepants The GOTOs were bugging me too .... a lot. VAR RETRIES = 0, LOCKED = FALSE, PW$ VAR VALID_PASSWORD$[0] 'READ THE LIST OF VALID PASSWORDS READ PW$ WHILE PW$ != "" PUSH VALID_PASSWORD$, PW$ READ PW$ WEND PW$ = GET_PASSWORD$() IF PW$ == "V360" THEN PRINT "MASTER, .... IT'S YOU!" IF PW$ != "" THEN LOG_IN ELSE PRINT "GAME OVER" ENDIF END DEF GET_PASSWORD$() VAR PW$, I, VALID IF LOCKED THEN PRINT "ACCESS DENIED" ELSE VALID = FALSE REPEAT INPUT "PASSWORD"; PW$ 'IS THAT A VALID PASSWORD? FOR I = 0 TO LEN(VALID_PASSWORD$) - 1 IF PW$ == VALID_PASSWORD$[I] THEN VALID = TRUE BREAK ENDIF NEXT I IF VALID == FALSE THEN RETRIES = RETRIES + 1 PRINT "INVALID PASSWORD." IF RETRIES > 3 THEN LOCKED = TRUE PW$ = "" PRINT "TOO MANY FAILED LOGINS. LOCKED!" ENDIF ENDIF UNTIL VALID OR LOCKED ENDIF RETURN PW$ END DEF LOG_IN PRINT "C:>" END @PASSWORDS DATA "PASSWORD", "V360", "" Here is my overly long take with some tricky edge cases to puzzle over. Note that the password list is data driven. You can add, edit, and delete passwords without altering the code outside of the data statement. The pw$ variable in get_password and the one at global scope are different variables with the same name. Spooky. If you call get password after your retries are up it will kick you out. The while/wend, repeat/until and for loops save you from making a bunch of line labels as do the functions. You could move the code into new programs and reuse it now. Get_password has () in the call because it returns a value. Log_in doesn't return a value so you don't use (). Posted
  • #30 ✎ 931 Y_ack or you could just not complicate things for someone clearly trying to learn Posted
  • #31 ✎ 83 seggiepants It was actually designed to be useful to someone just starting out and trying to learn. GOTO has been considered harmful to writing clean code since the 70s. If you are just starting out using GOTO/GOSUB will hurt you in the long run and naturally lead to unmaintainable spaghetti code. In the example I showed WHILE/WEND, FOR/NEXT, and a REPEAT/UNTIL loops. I even put in an decent example of BREAK to skip unneccesary processing. I showed the different DEF syntax for a function and a subroutine too. Learning those will help you write cleaner, more maintainable, more reusable, more readable code. There is a lot to study packed into less than 60 lines, but I do think it is worth studying. Posted
  • #32 ✎ 98 niconii Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies I agree with Lumage. Throwing a huge pile of concepts at someone all at once, while telling them the stuff they do understand is bad and wrong, is not a good way to teach someone. Yeah, GOTOs can contribute to hard-to-read code over time compared to more advanced control flow, but this is not an immediate problem that has to be addressed when they're still learning basic concepts like comparison operators. Program structure and code maintenance can be worried about later. It also strikes me as odd that this is all in the name of cleaner and more readable code, because the code you've given is fairly convoluted and difficult to follow. GET_PASSWORD$() could be rewritten as something like this: DEF CONTAINS(ARRAY[], ITEM) VAR I FOR I=0 TO LEN(ARRAY)-1 IF ARRAY[I]==ITEM THEN RETURN TRUE NEXT RETURN FALSE END DEF GET_PASSWORD$() VAR TRY,PW$ IF LOCKED THEN PRINT "ACCESS DENIED" RETURN "" ENDIF FOR TRY=1 TO 3 INPUT "PASSWORD";PW$ IF CONTAINS(VALID_PASSWORD$,PW$) THEN RETURN PW$ ELSE PRINT "INVALID PASSWORD." ENDIF NEXT PRINT "TOO MANY FAILED LOGINS. LOCKED!" LOCKED=TRUE RETURN "" END Posted
  • #33 ✎ 180 phil_ Scholar Received for knowing a great deal about programming topics Achievements osu! Is Awesome! I love osu! Express Yourself First Day Joined on the very first day of SmileBASIC Source Website My own take, while we're at it (to further modularize). Side note, this is purely functional with the exception of the CONTAINS$ function and PRINT statements. DEF CONTAINS$(PASSWORDS$[], WORD$) VAR I FOR I=0 TO LEN(PASSWORDS)-1 IF PASSWORDS[I]==WORD THEN RETURN WORD NEXT RETURN "" END DEF CHECK$(WORD$) IF WORD$=="" THEN PRINT "Invalid password, try again!" ELSE PRINT "Success!" ENDIF RETURN WORD$ END DEF CHECKPASS$(CHECKS%) VAR PASS$ IF CHECKS%==3 THEN PRINT "Access denied, too many password attempts!" RETURN "" ELSE LINPUT "Input password: ", PASS$ VAR TESTER$=CHECK$(CONTAINS$(PASS)) IF TESTER$=="" THEN RETURN CHECKPASS$(CHECKS% + 1) ELSE RETURN TESTER$ ENDIF END CHECKPASS$(0) I haven't tested this, and I haven't written SB in over a year, so please let me know if there are any problems. Posted Edited by phil_
1 2