I do have Doors CS7.1 (Beta 2) and I got xLib from a program I downloaded that needed xLib. I didn't know DCS does all that! Now I can free up some space on my calc. Thx.
bspymaster wrote:
I do have Doors CS7.1 (Beta 2) and I got xLib from a program I downloaded that needed xLib. I didn't know DCS does all that! Now I can free up some space on my calc. Thx.
My pleasure. So is everything working with regards to that? Pray continue to ask your questions.
Yes, my calculator works now, but as I was ,making a game, I tried to add cheats, but I keep getting an "error: Type" report. Here's the code:
:Input "Cheat:", str1
:If str1=MANYMONEYS
:then
:G+500->G
:Output (3,3,"Cheater"
:pause
:Goto B
***More if/then statements for cheats***
:Else
:Output (3,5,"Fail"
:Pause
:Goto B
:End
Any suggestions?
:Input "Cheat:", str1
:If str1=MANYMONEYS
:then
:G+500->G
:Output (3,3,"Cheater"
:pause
:Goto B
***More if/then statements for cheats***
:Else
:Output (3,5,"Fail"
:Pause
:Goto B
:End
Any suggestions?
You need quotes around the strings that you're checking:
Code:
As another tip, you should try to avoid using Gotos, especially like that. If you need the goto, you could put it after all of the If/Then/Else statements, since it looks like they all jump to B, so like this:
Code:
Code:
:Input "Cheat:", str1
:If str1="MANYMONEYS"
:then
:G+500->G
:Output (3,3,"Cheater"
:pause
:Goto B
***More if/then statements for cheats***
:Else
:Output (3,5,"Fail"
:Pause
:Goto B
:End
As another tip, you should try to avoid using Gotos, especially like that. If you need the goto, you could put it after all of the If/Then/Else statements, since it looks like they all jump to B, so like this:
Code:
:Input "Cheat:", str1
:If str1="MANYMONEYS"
:then
:G+500->G
:Output (3,3,"Cheater"
:pause
***More if/then statements for cheats***
:Else
:Output (3,5,"Fail"
:Pause
:End
:Goto B
Thanks Merth. To further clarify, putting Gotos inside Then/End statements creates something called a memory leak, because the calculator will be searching for the End connected to the Then it saw, but will never find it.
I used to do that all the time, but I learned my lesson. However, you can put:
Code:
because if there is only one command after an If, it doesn't need the Then, so the Goto doesn't cause a memory leak.
Whew.
Code:
If X=1337
Goto MM
because if there is only one command after an If, it doesn't need the Then, so the Goto doesn't cause a memory leak.
Whew.
c.sprinkle wrote:
I used to do that all the time, but I learned my lesson. However, you can put:
Code:
because if there is only one command after an If, it doesn't need the Then, so the Goto doesn't cause a memory leak.
Whew.
Yup, that's a good first-pass way to avoid a memory leak. However, if that If/Goto is inside a While, Repeat, or For loop, then you still have a problem, and you'll have to find a more creative fix like modifying the escape conditions of the loop. Code:
If X=1337
Goto MM
because if there is only one command after an If, it doesn't need the Then, so the Goto doesn't cause a memory leak.
Whew.
Sometimes, to get out of a For() loop, I set the variable I am using for the loop as the number that would exit the loop:
Example:
Code:
This is equivalent to the "break" statement in computer languages (I think).
Example:
Code:
For(X,1,128
//code
If (some condition)
128->X
End
This is equivalent to the "break" statement in computer languages (I think).
KermMartian wrote:
Thanks Merth. To further clarify, putting Gotos inside Then/End statements creates something called a memory leak, because the calculator will be searching for the End connected to the Then it saw, but will never find it.
Ah... so that's why my calculator freaks out... Thanks, KermMartian. also, thanks for the quoting tip. Didn't know it had to be in parentheses.
Csprinkle: you can do that? That'll be useful in cutting down program size as well. Thanks.
souvik1997: So is that what the for loop variable is used for? Whenever I try to use it, it never works.
Indeed, you can omit the "Then" and the corresponding 'End" after the "If" if there is only one command in the If-Then block.
souvik1997 wrote:
Indeed, you can omit the "Then" and the corresponding 'End" after the "If" if there is only one command in the If-Then block.
Yup, this. And c.sprinkle was correct about how to escape from For() loops.
so next question: how do I get rid of "Error: Mem" problems. I'm assuming it's some sort of memory leak, but it appears at random times (I've timed it). Got any ideas?
Are you creating or storing large variables in your program? If so, try to free up as much RAM as possible when starting your program, because running out of memory causes the ERR:MEM errors. You can do this by using the Delvar command.
And another thing is that each time you use Goto to get out of a loop or If /Then block, it creates a small memory leak.
All the things said above. If you have Goto in a Then/End, a For()/End, a While()/End, or a Repeat()/End, you're leaking memory.
Ahhh... It all makes sense now. I have a bad habit of using the Goto command overextensively. Any suggestions on getting rid of that? I've noticed some people use a command like the one below for arrow key movement, but I can't figure out how it works exactly.
Code:
This might not be exactly it, but it was something like this. Hmmm...
Code:
:X-4(A=24)X+4(A=26)Y+4(A=25)Y-4(A=34)
This might not be exactly it, but it was something like this. Hmmm...
Yup, that uses the fact than (Variable=Number) returns 1 for true and 0 for false. If you can show use some of your code in question, I can (we can) try to both help you root out the memory leaks and show you how to use that style of optimization.
As Kerm said, in Basic, a conditional returns 1 if it's true and 0 if it's false. Thus,
Code:
evaluates the conditionals, then evaluates the rest. Let's say we have pressed the DOWN key when X is 5 and Y is 17:
So, we now have:
Code:
Which evaluates to:
Code:
and we end up with:
Code:
That help?
Code:
getKey->A
X-4(A=24)+4(A=26)->X
Y+4(A=25)-4(A=34)->Y
evaluates the conditionals, then evaluates the rest. Let's say we have pressed the DOWN key when X is 5 and Y is 17:
So, we now have:
Code:
5-4(0)+4(0)->X
17+4(0)-4(1)->Y
Which evaluates to:
Code:
5->X
17-4->Y
and we end up with:
Code:
5->X
13->Y
That help?
And to take Goto s out, you can usually replace them with loops.
Code:
I'm not sure what Lbl B is, but if it's at the beginning of this code section, you can replace it with a loop like While /End or Repeat /End. If it's just a routine that's run after the code section, try moving all of Lbl B right after the End in your code and get rid of the Goto s, and it would still work.
Code:
:Input "Cheat:", str1
:If str1=MANYMONEYS
:then
:G+500->G
:Output (3,3,"Cheater"
:pause
:Goto B
***More if/then statements for cheats***
:Else
:Output (3,5,"Fail"
:Pause
:Goto B
:End
I'm not sure what Lbl B is, but if it's at the beginning of this code section, you can replace it with a loop like While /End or Repeat /End. If it's just a routine that's run after the code section, try moving all of Lbl B right after the End in your code and get rid of the Goto s, and it would still work.
Csprinkle: so you would write:
:getKey->A
:X-4(A=24)+4(A=26)->X
:Y+4(A=25)-4(A=34)->Y
to get it to work?
Deep thought: Lbl B is a lot further up. it's actually the main screen of my game (go to web.me.com/twodomers/crossfire_studios and download "Battlewar2.zip" to view the whole program. Enjoy it, too ) do those loops still hold?
:getKey->A
:X-4(A=24)+4(A=26)->X
:Y+4(A=25)-4(A=34)->Y
to get it to work?
Deep thought: Lbl B is a lot further up. it's actually the main screen of my game (go to web.me.com/twodomers/crossfire_studios and download "Battlewar2.zip" to view the whole program. Enjoy it, too ) do those loops still hold?
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
» Go to Registration page
» Goto page Previous 1, 2, 3, 4 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 2 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
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