I use this code several times. Is there a way to store this in a string or a variable instead of writing it out every time?

Code:

Repeat Ans=105
getKey
End
ClrHome
21tmccauley wrote:
I use this code several times. Is there a way to store this in a string or a variable instead of writing it out every time?

Code:

Repeat Ans=105
getKey
End
ClrHome


You can put this into a subprogram (another program) and recall the program name where you want to use that code. (2nd+sto) (prgm+<)(scroll to name)(enter)
jcgter777 wrote:
You can put this into a subprogram (another program) and recall the program name where you want to use that code. (2nd+sto) (prgm+<)(scroll to name)(enter)


That will require multiple programs though. First of all, this piece of code (The getKey loop) can be replaced by a Pause command. But, if you want a copy and paste method, write the code out like this: "Repeat Ans=105:getKey:End:ClrHome"->Str1. Then, in your program whenever you want to paste this code, use Rcl Str1. Or, store this in a subprogram but instead of selecting the program name, use rcl and then the program, which will copy and paste it instead of just calling it.
Would it work to implement a "Skills" factor whereby making certain choices, your intelligence, or charisma improves, furthermore allowing different choices to be made?

If I did, could this work by adding 1 to a variable each time you make a decision that affects that skill, and having each variable correspond to a trait (Ex. A->Intellengce if A=3 that choice is available)

If anyone has any other ideas or advice, I would appreciate it Very Happy Very Happy Good Idea
According to SourceCoder 3, there is an error on the part in the code where the random integer is chosen. Here is the code for it

Code:

ClrHome   
   randInt(1,3)->X
   If X=1:Then
      Disp "Aint math fun?"
      A+1->A
      B+1->B

I don't see what is wrong. Thanks for the help.
The randInt command should not be tabbed in like it is. For that matter, all the code shouldn't be tabbed in as much as it is. Razz
MateoConLechuga wrote:
The randInt command should not be tabbed in like it is. For that matter, all the code shouldn't be tabbed in as much as it is. Razz

As I put it in, it tabbed by its self. I'll fix it. Thanks!
I removed all of the tabs and now the code looks like this

Code:

Lbl G
ClrHome   
randInt(1,3)->X
If X=1:Then
Disp "Aint math fun?"
Wait 2
A+1->A
B+1->B
End

It still says there is an error at "randInt(1,3)->x, and nothing I do seems to fix it.
You have extra spaces after the ClrHome command. Please remove them.
MateoConLechuga wrote:
You have extra spaces after the ClrHome command. Please remove them.

There is nothing I hate more than spaces Mad Smile
For some reason when the program runs this Lbl, it ends the program. Why does it do this?

Code:

Lbl F
If A>=12:Then
randInt(1,5)->Z
If Z=4:Then
If B>=8:Then
Disp "You've won the","science fair. You gain","5 intellegence
B+5->B
End
Goto M
If A>=15:Then
randInt(1,5)->Z
If Z=3:Then
If C>=8:Then
Disp "You got a date!","Congratulations. You","gain 5 charisma"
C+5->C
End
Goto M
If A>=20:Then
Goto L
Else
Disp "You are at school"
Pause " "
Disregard my last post. I am trying to write some code that checks if two variables meet requirements. I want it to check the variables A and B. First, A needs to be larger than 8. If it is it generates a random number between 1 and 2, and stores it as Z. It then should if Z equals 1 and if B is larger than 8. It should then display Z equals 1. If Z equals two, then it does the same thing but instead displays Z equals 2. This is just a proof of concept. Right now, when I run it displays Z equals one no matter what. It also gives a syntax error at the End and the end of the if-then loop.

Code:

Input "A",A
Input "B",B
If A≥8
Then
randInt(1,2)→Z
Disp Z
Pause " "
Else
Disp "A is too small"
Return
End
If Z=1
If B≥8
Disp "Z=1"
Pause " "
End
End
Return
If Z=2
If B≥8
Disp "Z=2"
Pause " "
End
End
Return
1: You can just type
Code:
Pause

2: Return (in basic terms) exits the program.
3: It should be

Code:
If Z=1 and B≥8:Then:Disp"Z=1":Pause:End
And the same thing with the reverse at the end of the program.
In my code, it always stops with a syntax error at the 2nd to last "End". There isn't an extra space this time Very Happy

Code:

Then
   randInt(1,5)->Z
   If Z=4
   and
   C>=8
   Then
      Disp "Congratulations, you got a","date. You gain 5 charisma
      C+5->C
   End
End
If A>=20
Then
   Goto O
End
That's not quite how the ' and ' command works

Code:
   If Z=4
   and
   C>=8
   Then

Every condition should be on the same line as the If statement it's tied to.
It should look like this:

Code:
 
If Z=4 and C>=8
Then



Also

Code:
If A>=20
Then
   Goto O
End

This is a big no-no, when you use 'Goto' within an If statement or loop it creates memory leak. Memory leaks will greatly slow down your program and will eventually make your program crash due to a lack of RAM. You can learn more about them here.
Also when you only have one line of code after the If statement, you don't need a 'Then' or 'End'. Single line If statements also don't cause memory leaks. Therefore that code could look like this:

Code:
If A>=20
Goto O

(Please ignore the random spacing if it's there)
TheLastMillennial wrote:
Have you tried adding an Else before the End?
Also

Code:
If A>=20
Then
   Goto O
End

This is a big no-no, when you use 'Goto' within an If statement or loop it creates memory leak. Memory leaks will greatly slow down your program and will eventually make your program crash due to a lack of RAM. You can learn more about them here.
Also when you only have one line of code after the If statement, you don't need a 'Then' or 'End'. Single line If statements also don't cause memory leaks. Therefore that code could look like this:

Code:
If A>=20
Goto O

(Please ignore the random spacing)

Wow Thanks! I had no idea about memory leaks, and that could have messed me up. I really appreciate it! Also I changed the code to this, and it puts the syntax error at the "Else"

Code:

If A>=15
Then
   randInt(1,5)->Z
   If Z=4
   and
   C>=8
   Then
      Disp "Congratulations, you got a","date. You gain 5 charisma
      C+5->C
   End
   Else
End
If A>=20
Goto O
21tmccauley wrote:
Wow Thanks! I had no idea about memory leaks, and that could have messed me up. I really appreciate it! Also I changed the code to this, and it puts the syntax error at the "Else"

Code:

If A>=15
Then
   randInt(1,5)->Z
   If Z=4
   and
   C>=8
   Then
      Disp "Congratulations, you got a","date. You gain 5 charisma
      C+5->C
   End
   Else
End
If A>=20
Goto O

I don't see why that would throw an error on the Else line, however, the and is still used incorrectly. Also, the Else statement is useless here because there is no code block after it (if the condition is not true, do nothing) so you could just remove it entirely.

Code:

If A>=15
Then
   randInt(1,5)->Z
   If Z=4 and C>=8
   Then
      Disp "Congratulations, you got a","date. You gain 5 charisma
      C+5->C
   End
End
If A>=20
Goto O
After recently learning about memory leaks, how would I have this code without the goto inside of the if-then loop?

Code:

Lbl V
If E>=10
Then
   ClrHome
   Disp "You need to be very lucky","to be a gold miner. Be","careful, while this job can","be highly rewarding, it can","also give you very little
   Pause " "
   ClrHome
   Disp "If you want to go back","to pick a more stable job","go now
   Pause " "
   Menu("Do you want to go back","Yes",P,"No",W
Else
   ClrHome
   Disp "You need more luck for","this job
   Pause " "
   Goto P
End
Since your menu only contains two options, we can use a Boolean variable to store whether to go to Label P or W after exiting the if...then...else...end structure. Truly, a very simple custom menu might work better, but you can do whatever you want. For example:


Code:

1->Booleanvariable  //since the default after the else is to go to P
If..then...

...

//get Boolean value from user

Else

...

End
If not(booleanvariable
Goto W
If booleanvariable
Goto P
I have absolutely no idea how to make custom menus. Thanks for the advice.
  
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 3 of 4
» 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