this program will allow you to open games (provided you tweak the code), play quick games vs the calculator, and learn facts.
the password is preset to 2110 but you can change it in the code.
this is what i have written so far (the rock paper and scissors wont work; if someone sees why, please tell me)


Code:
//"Boot" screen
ClrHome
Disp "BOOTING...
For(I,1,2500)
End
ClrHome
Disp "SYSTEM ONLINE"
For(I,1,500)
End
Disp "USER ONLINE"
For(I,1,500)
End
Disp "INITIALIZING..."
For(I,1,500)
End
ClrHome
Disp "MODULE READY"
For(I,1,500)
End

//Passcode
Input "AUTH CODE?",C
If C≠2110
Then
Disp "FAILURE"
Pause
Stop
Else
Goto P

//Greeting
Lbl P
ClrHome
Disp "GREETINGS"
Disp "STATUS: NOMINAL"
Disp "READY FOR INPUT"
Pause
ClrHome

//Main menu
Lbl D
Menu("MAIN","PLAY GAME",B,"CHAT",E,"QUIT",C)

//Gamescreen
Lbl B
Disp "NO GAMES YET"
Disp "INSTALLED"
Pause
Disp "GET GAMES HERE:"
Disp "CEMETECH.NET"
Pause
ClrHome
Goto D

//Quick quit
Lbl C
ClrHome
Stop

//Calc chat
Lbl E
Menu("WHAT DO U WANT TO DO?","FACTS",F,"PLAY GAME VS CALC",G,"BACK",I)

//Games to play
Lbl G
Menu("GAMES VS CALC","COIN TOSS",J,"R.P.S.",K,"BACK",I)

//Coin toss
Lbl J
Disp "COIN TOSS"
randInt(1,2)→Z
Pause
Disp
If Z=1
Then
Disp "ITS TAILS!"
Pause
ClrHome
Goto G
Else
Disp "ITS HEADS!"
Pause
ClrHome
Goto G

//Back
Lbl I
Goto D

//Rock, paper and scissors (in progress)
Lbl K
Disp "R.P.S"
randInt(1,3)→R
If R=1
Then
ROCK→Str1
If R=2
Then
PAPER→Str1
Else
SCISSORS→Str1
Disp "CHOOSE"
Input "1=R,2=P,3=S",T
Disp "CALC: "Str1
If T=1
Then
ROCK→Str2
If T=2
Then
PAPER→Str2
Else
SCISSORS→Str2
Disp "USER: "Str2
Pause
ClrHome
Goto G
If you are trying to make something password protected, if you want it to actually be secure, try implementing some kind of algorithm that encrypts and decrypts the password. Currently, all somebody would have to do to get the password would be to look inside of the program.
claculator wrote:
If you are trying to make something password protected, if you want it to actually be secure, try implementing some kind of algorithm that encrypts and decrypts the password. Currently, all somebody would have to do to get the password would be to look inside of the program.

i will, thx 🙂
do u know of any way to do this?

Code:
// random program stuff
Input "New password: ",Str1
// Caesar cipher, the stereotypical simple "encryption" method
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890A"→Str0
" "→Str2
For(I,1,length(Str1))
Str2+sub(Str0,inString(Str0,sub(Str1,I,1))+1,1)→Str2
End
Str2→Str1
// Decryption
Input "Password: ", Str2
" "→Str3
For(I,1,length(Str2))
Str3+sub(Str0,inString(Str0,sub(Str2,I,1))+1,1)→Str3
End
If Str3=Str1:Then
// The rest of the program
// I wrote that off the top of my head in like a minute; there is *undoubtedly* a much more efficient way to do that

Of course, for any encryption method in TI-BASIC, anyone could still just look inside of your program and decipher how your password is encrypted, but the more encryption there is, the harder it is for some average Joe to decrypt it.
i made some progress but still need to make sure that the program does not ask for a new code each time, thank u for ur help!

the updated code

Code:
"Boot screen"
ClrHome
Disp "Booting...
For(I,1,2500)
End
ClrHome
Disp "System online"
For(I,1,500)
End
Disp "User online"
For(I,1,500)
End
Disp "Initializing..."
For(I,1,500)
End
ClrHome
Disp "Module ready"
For(I,1,500)
End

"random program stuff"
Input "New password: ",Str1
"Caesar cipher, the stereotypical simple encryption method"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890A"→Str0
" "→Str2
For(I,1,length(Str1))
Str2+sub(Str0,inString(Str0,sub(Str1,I,1))+1,1)→Str2
End
Str2→Str1
"Decryption"
Input "Password: ",Str2
" "→Str3
For(I,1,length(Str2))
Str3+sub(Str0,inString(Str0,sub(Str2,I,1))+1,1)→Str3
End
If Str3=Str1
Then
Goto D
Else
Stop

"Greeting"
Lbl P
ClrHome
Disp "Greetings"
Disp "Status: Nominal"
Disp "Ready for input"
Pause
ClrHome

"Main menu"
Lbl D
Menu("MAIN","Play game",B,"Chat",E,"Quit",C)

"Gamescreen"
Lbl B
Disp "No games yet"
Disp "Installed"
Pause
Disp "Get games here:"
Disp "cemetech.net"
Pause
ClrHome
Goto D

"Quick quit"
Lbl C
ClrHome
Stop

"Calc chat"
Lbl E
Menu("CALC CHAT","Facts",F,"Game vs calc",G,"Back",I)

"Games to play"
Lbl G
Menu("Games vs calc","Coin toss",J,"R.P.S.",K,"Back",I)

"Coin toss"
Lbl J
Disp "Coin toss"
randInt(1,2)→Z
Pause
Disp
If Z=1
Then
Disp "Its tails!"
Pause
ClrHome
Goto G
Else
Disp "Its heads!"
Pause
ClrHome
Goto G

"Back"
Lbl I
Goto D


something like this should work, right? (to make sure it does not ask for a new code each time)

Code:
"random program stuff"
If Str1=""
Then
Input "New password: ",Str1
I'm glad you kept my worthless comments 🙂
TI-BASIC is actually a little finicky about empty strings, so I'd use

Code:
If length(Str1)<1
Then
//I'd also add a label here for accessing password resetting from the main menu
Lbl P
//everything else

and then I'd also add the option in the menu to set up a new password.
i implemented it but i got an error ☹️
here is the code:

Code:
"Boot screen"
ClrHome
Disp "Booting...
For(I,1,2500)
End
ClrHome
Disp "System online"
For(I,1,500)
End
Disp "User online"
For(I,1,500)
End
Disp "Initializing..."
For(I,1,500)
End
ClrHome
Disp "Module ready"
For(I,1,500)
End


"Choose new passcode"
If length(Str1)<1
Then
Lbl Q   
Disp "Change your passcode"
Pause    
Input "New password: ",Str1
Goto D
   
"Encryption
"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890A"→Str0
" "→Str2
For(I,1,length(Str1))
Str2+sub(Str0,inString(Str0,sub(Str1,I,1))+1,1)→Str2
End
Str2→Str1
"Decryption"
Input "Password: ",Str2
" "→Str3
For(I,1,length(Str2))
Str3+sub(Str0,inString(Str0,sub(Str2,I,1))+1,1)→Str3
End
If Str3=Str1
Then
Goto D
Else
Stop

"Greeting"
Lbl P
ClrHome
Disp "Greetings"
Disp "Status: Nominal"
Disp "Ready for input"
Pause
ClrHome

"Main menu"
Lbl D
Menu("MAIN","Play game",B,"Chat",E,"Change password",Q,"Quit",C)

"Gamescreen"
Lbl B
Disp "No games yet"
Disp "Installed"
Pause
Disp "Get games here:"
Disp "cemetech.net"
Pause
ClrHome
Goto D

"Quick quit"
Lbl C
ClrHome
Stop

"Calc chat"
Lbl E
Menu("CALC CHAT","Facts",F,"Game vs calc",G,"Back",I)

"Games to play"
Lbl G
Menu("Games vs calc","Coin toss",J,"R.P.S.",K,"Back",I)

"Coin toss"
Lbl J
Disp "Coin toss"
randInt(1,2)→Z
Pause
Disp
If Z=1
Then
Disp "Its tails!"
Pause
ClrHome
Goto G
Else
Disp "Its heads!"
Pause
ClrHome
Goto G

"Back"
Lbl I
Goto D

Code:
Input "New password: ",Str1
Goto D

First, the Goto D should be after the decryption. Second, you need to be careful with Labels and Gotos because if you put them inside of an if statement or loop you can end up with memory leaks. I don't have the effort or time to explain that, so here: Memory Leaks

I'm not entirely sure, but my gut says that there's a memory leak since the Lbl Q is inside of an If statement. I'd put it right before the If statement and figure something out for resetting the password even if Str1 isn't empty. There are a number of other potential memory leaks but evidently none of them are significant enough to cause an error.

Let me know if you get any other errors. Or let ChatGPT know, frankly. Say what you will about it, but it probably understands TI-BASIC better than I do. My advice with AI programming is to always have a person check the code afterwards, though.
I had ChatGPT write it but I still got an error.

Code:
ClrHome
Disp "Booting..."
For(I,1,2500)
End
ClrHome
Disp "System online"
For(I,1,500)
End
Disp "User online"
For(I,1,500)
End
Disp "Initializing..."
For(I,1,500)
End
ClrHome
Disp "Module ready"
For(I,1,500)
End

"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890A"→Str0

If Str1=""
Goto N
Goto A

Lbl N
ClrHome
Disp "Change your passcode"
Pause
Input "New password: ",Str2
Goto EN

Lbl A
ClrHome
Input "Password: ",Str2
Goto ENCHK

Lbl EN
""→Str3
For(I,1,length(Str2))
Str3+sub(Str0,inString(Str0,sub(Str2,I,1))+1,1)→Str3
End
Str3→Str1
Goto P

Lbl ENCHK
""→Str3
For(I,1,length(Str2))
Str3+sub(Str0,inString(Str0,sub(Str2,I,1))+1,1)→Str3
End
If Str3=Str1
Goto P
Stop

Lbl P
ClrHome
Disp "Greetings"
Pause
Goto D

I do not see any errors but you'd know better then me.
What error are you getting?
right after it displays "module ready" I get an undefined error. when I selected "goto" I went to the line: If Str1="" . but maybe because its not the "length" style anyway.
edit: I got the same error when I changed the code to include the length line too.
can someone please try this on a monochrome ti 8x calculator to make sure its not just me?
Try storing something into Str1 and then running it, that happened to me when I was making a program. Maybe just don't use the line and instead store " " into Str1 or something of that sort.
ok, i tried that but it just ends the program when i enter the passcode. but when i store "" into string 1 i get a undefined error again. so it must be the creation of the new passcode that is messing it up. or the decryption.
edit: i think it is because i made the passcode outside of the program so it never encrypted it.
You need to store something (i recommend a space) into it, TI-BASIC gives an error when a string has nothing in it (I don't know why, it just happens)
I kinda gave up on this and decided to make a a plain chatbot (no password, no games, no launcher) with instring commands for detecting words. i will post it when i get a decent amount done.
i might get back to this at some point though.
I was looking at your code, and here's what I was able to come up with:
Code:
SetUpEditor |LPASSW
ClrHome
Disp "BOOTING...
rand(450
ClrHome
Disp "SYSTEM ONLINE
rand(|E2
Disp "USER ONLINE
rand(|E2
Disp "INITIALIZING...
rand(|E2
ClrHome
Disp "MODULE READY
ClrHome
If not(dim(|LPASSW
Then
   Input "NEW PASSWORD:",Str1
   For(I,1,length(Str1
      inString("1234567890",sub(Str1,I,1->|LPASSW(I
   End
Else
   "
   Input "PASSWORD:",Str1
   For(I,1,dim(|LPASSW
      Ans+sub("1234567890",|LPASSW(I),1
   End
   If Str1!=sub(Ans,2,length(Ans)-1
   Then
      Pause "WRONG
      Return
   End
End
rand(|E2
Disp "GREETINGS
Disp "STATUS:NOMINAL
Pause "READY FOR INPUT
Lbl D
Menu("MAIN","PLAY GAME",B,"CHAT",E,"QUIT",C
Lbl B
ClrHome
Disp "NO GAMES YET INSTALLED","GET GAMES HERE:
Pause "CEMETECH.NET
Goto D
Lbl E
Menu("WHAT DO U WANT TO DO?","FACTS",F,"PLAY GAME VS CALC",G,"BACK",D
Lbl F
ClrHome
Pause "FACTS..\.
Goto E
Lbl G
Menu("GAMES VS CALC","COIN TOSS",J,"R.P.S.",K,"BACK",E
Lbl J
ClrHome
Pause "COIN TOSS
Pause "ITS "+sub("HEADS!TAILS!",6randInt(1,2)-5,6
Goto G
Lbl K
ClrHome
Disp "1=ROCK 2=PAPER 3=SCISSORS
Prompt A
randInt(1,3->R
Disp "YOU CHOSE "+sub("ROCK    PAPER   SCISSORS",8A-7,8
Disp "CALC CHOSE "+sub("ROCK    PAPER   SCISSORS",8Ans-7,8
A-R
If Ans
Then
   sub("BOTYOU",3max(Ans={1,~2})+1,3)+" WON!
Else
   "TIE!
End
Pause Ans
Goto G
Lbl C
ClrHome
You can copy/paste that into SourceCoder and send it to your calc.


That's a lot, so let's go through it piece by piece:

Code:
SetUpEditor |LPASSW
SetUpEditor is a very powerful list command. It creates the list if it does not already exist, unarchives it if it is archived, and does nothing if it already exists and is RAM. So after this line, the list ʟPASSW is guaranteed to be defined and unarchived.

Code:
ClrHome
Disp "BOOTING...
rand(450
ClrHome
Disp "SYSTEM ONLINE
rand(|E2
Disp "USER ONLINE
rand(|E2
Disp "INITIALIZING...
rand(|E2
ClrHome
Disp "MODULE READY
ClrHome
This part is nearly identical to yours. The main difference is that I replaced the For( loops with rand(#. This relies on the fact that it takes substantial time to generate a random list. The number in the rand command is the number of random elements the list should have, so increasing the number will make it make a longer delay. I tried to keep about the same delay as your For( loops, but you can adjust the numbers to your liking.

Code:
If not(dim(|LPASSW
Then
This will determine whether or not ʟPASSW has any elements in it (evidence of a password being set).

Code:
Input "NEW PASSWORD:",Str1
Prompt for a new password and store it into Str1.

Code:
For(I,1,length(Str1
   inString("1234567890",sub(Str1,I,1->|LPASSW(I
End
This recursively goes through Str1 and stores the number in the string into ʟPASSW. If Str1 was "1472", then ʟPASSW is now {1,4,7,2}

Code:
Else
"
Input "PASSWORD:",Str1
If the password is already defined, put an string " " in Ans. Note that there must be a space in the string, otherwise it will cause an error. Next, we ask the user to enter the password.

Code:
For(I,1,dim(|LPASSW
   Ans+sub("1234567890",|LPASSW(I),1
End
This goes through ʟPASSW and adds the character (which is a string of 0-9) to the space character in Ans. Since this updates Ans on every loop iteration, we can simply add to the string and it will grow in length. If ʟPASSW is {1,4,7,2}, then Ans will now be " 1472". The beginning space is still present from before the For( loop.

Code:
If Str1!=sub(Ans,2,length(Ans)-1
Then
   Pause "WRONG
   Return
End
End
The inline sub( command chops off the first character of the string in Ans, which contains the correct password. If Str1 (what the user just entered) is not equal to Ans without the first character (the space), then the password is incorrect. If it is incorrect, then it displays "WRONG", waits for the user to press enter, then quits the program.

Code:
rand(|E2
Disp "GREETINGS
Disp "STATUS: NOMINAL
Pause "READY FOR INPUT
I removed an unnecessary Lbl (it was never called) and chopped off a few bytes.

Code:
Lbl D
Menu("MAIN","PLAY GAME",B,"CHAT",E,"QUIT",C
Lbl B
ClrHome
Disp "NO GAMES YET INSTALLED","GET GAMES HERE:
Pause "CEMETECH.NET
Goto D
Lbl E
Menu("WHAT DO U WANT TO DO?","FACTS",F,"PLAY GAME VS CALC",G,"BACK",D
This is nearly identical to yours. I was able to save a handful of bytes here. I am quite curious how running programs will work though.

Code:
Lbl F
ClrHome
Pause "FACTS..\.
Goto E
I just added this small piece of code in to stop the ERR:LBL from showing up. I would replace it with a randInt(1,[number_of_facts]), and then use different Disp commands to determine which fact to display. The rest is pretty self-explanatory.

Code:
Lbl G
Menu("GAMES VS CALC","COIN TOSS",J,"R.P.S.",K,"BACK",E
I think this is the same as yours.

I was able to optimize the coin flip pretty heavily. Here's how it works:

Code:
Lbl J
The label to jump to, obviously.

Code:
ClrHome
Pause "COIN TOSS
Clear the screen and display the text.

Code:
Pause "ITS "+sub("HEADS!TAILS!",6randInt(1,2)-5,6
Add the string "ITS" with the result of the sub( command. Sub( returns a substring of larger string, starting at the second argument and continuing for the third argument's characters. In other words, sub("HELLO",2,3) would return "ELL". Here, we begin at a random number (either 1 or 2 since that's the number of possibilities) multiplied by 6 (the length of each possible result ("HEADS!" or "TAILS")) minus 5, bringing us to the beginning of the string. Therefore, depending on the randInt, it will either begin at 1 or 7. It will then continue for 6 characters, the lengths of both "HEADS!" and "TAILS!". It will display the result and wait for the user to press enter.

Code:
Goto G
Jump back to the menu.

I was also able to optimize a whole lot out of the Rock, paper, scissors game. Let's go through that too.

Code:
Lbl K
ClrHome
The label to jump to, then clear the home screen.

Code:
Disp "1=ROCK 2=PAPER 3=SCISSORS
Prompt A
Tell the user what each number uses which object, and allows them to type in a number 1-3. Both the user and the bot will have their object encoded as a 1, 2, or 3 (rock, paper, and scissors respectively).

Code:
randInt(1,3->R
The "bot" picks a random action, represented by 1-3.

Code:
Disp "YOU CHOSE "+sub("ROCK    PAPER   SCISSORS",8A-7,8
Disp "CALC CHOSE "+sub("ROCK    PAPER   SCISSORS",8Ans-7,8
This displays the string "YOU CHOSE" with a sub( command determining the text version of which object they chose. I won't re-explain how sub( works, but each weapon is increased with spaces to occupy 8 character spaces because they must all be the same length, and "SCISSORS" is 8 letters long. The second line is nearly the same as the first, but is dependent on the bot's choice (Ans) instead of the user's (A).

Code:
A-R
I hope you can figure this one out...
It uses an algorithm I actually discovered while I was making this today. If you subtract the bot's choice from the user's choice, it will return a number from -2 to 2 inclusive. The result actually indicates who won, with -2 or 1 being a win for the user, -1 or 2 being a win for the bot, and 0 being a tie.

Code:
If Ans
Then
If the aforementioned result is non-zero, or not a tie...

Code:
sub("BOTYOU",3max(Ans={1,~2})+1,3)+" WON!
Return either "BOT" or "YOU" in another sub( command. max(Ans=(1,~2} is basically a fancy way of saying Ans=1 or Ans=-2. If Ans=1 or -2, then it will return "YOU" and if not, it will display "BOT", then tack " WON!" onto the end.

Code:
Else
"TIE!
End
If A-R is 0 and a tie has occurred, simply put "TIE!" in Ans.

Code:
Pause Ans
Goto G
Display whatever is in Ans (either "BOT/YOU WON!" or "TIE!"), wait for the user to press enter, and return to the game menu.

Code:
Lbl C
ClrHome
This is the label to jump to when exiting the program.

There might be a few more bytes that can be saved through optimizations, but that's the best I could do.

Now, I'll just add a few useful tips:

• You never need closing parenthesis, brackets, braces, or quotes if they are at the end of a line or immediately before a → variable assignment. For example,

Code:
 Disp "TEXT"
can be
 Disp "TEXT

 {1,2,3}→ʟLIST
can be
 {1,2,3→ʟLIST

 5(A+2)→A
can be
 5(A+2→A


• You can display a string and pause on a single line. For example,

Code:
 Disp "TEXT"
 Pause
can be
Pause "TEXT"
The only disadvantage that I can think of with this is that it also puts "TEXT" in Ans, but that's often unimportant.

• Making a delay with a For( loop is inefficient. You can instead use rand(# for a delay while using many fewer bytes.

• The sub( command is extremely useful when displaying different strings. For more information on it, look here.

• Ans is great when saving bytes. It always contains the most recent result of an evaluation, which can be updated by simply having something on a line by itself, a variable store, or displaying something at a Pause.


That's all I can think of right now. I would recommend looking at http://tibasicdev.wikidot.com/ if you haven't already; it has documentation on every TI-Basic command, useful reference pages, code routines, optimization and code structure help, example programs, and tons of other useful things to learn from.

I hope my advice and optimized code was useful! If you're confused by anything about my code, feel free to ask. I hope you continue to work on your project, but it's okay if you just want to focus on a plain chatbot. Regardless of what you work on, good luck and I hope to see it on my own calculator sometime!
Thank you so much! Maybe after i finish the chatbot i will get back to this!
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement