How do you suppose I not call them over and over?
Try using the Return command... That way, it will return to the calling program... In the case of ZEN4, just take off ZEN2, and it will automatically return back to the calling program...
dopeheaddude wrote:
As I understand, the more it runs, the more memory is taken. The more memory is taken, the more it lags.

A) Why does it take more and more memory? I don't understand the concept...
B) How can I stop it from happening? Currently, I can go about 10-20 minutes without a memory error...


A)

Code:
:label b
:if 1
:then
:goto b
:end


Look at that for a second. It will continually follow this:

if 1 (TRUE)
then (LOOK FOR "End")
goto b
if 1 (TRUE)
then (LOOK FOR 2 "End"s)
goto b
if 1 (TRUE)
then (LOOK FOR 3 "End"s)
etc....

as you can see, it never reaches the "end" after the goto because the program jumps to a different spot, hence it is continually looking for ends that it will never get to, and continually counting for ends takes more and more memory with no way for the stack to unwind

B) I think there are "semi-h.a.cks" that get around the problem while still using goto's, but the better way is to simply avoid using goto's and jump's unless it is necessary

If you MUST use a goto, then don't use an if-then statement, but just an if statement like so:


Code:
:label a
:0->j
:if 1
:then
:do some stuff
:1->j
:end
:if j
:goto a


This will essentially do the same thing above (get stuck in an infinite loop), only it will never run out of memory, and i'll walk thru it again to demonstrate.

0->j (j = 0)
if 1 (TRUE)
then (LOOK FOR "end")
stuff (STUFF)
1->j (j = 1)
end (FOUND "end" - "end"s left to find: 0)
if j (TRUE)
goto a

as you can see, when it jumps back to the top it is no longer looking for any "end"s, and therefore won't run out of memory. In case you didn't know, doing just an "if" with no "then" makes it only apply to the next line, and does not need an "end".

Note: the line "do some stuff" is optional, and if it isn't needed, then you can shorten it to simply:


Code:
label c
if 1
goto c


It is, however, better coding practice to avoid goto's and jump's in the first place
Looking through what I missed, I see this.
Quote:
As I understand, the more it runs, the more memory is taken. The more memory is taken, the more it lags.
There is actually NO SUCH THING as program lag! It's just gotos and subroutines. To stop it:

A) Don't use Lbl/Goto. Ever.
B) When calling subroutines, make sure that doesn't recall the caller.
Thank you Kll for that! I think I have that Goto problem settled! Wink

TI-Freak8x wrote:
Try using the Return command... That way, it will return to the calling program...

I can use Return in ZEN4, becuase ZEN2 called it, but if I put Return in
ZEN2, it would go to ZEN1, because that calls ZEN2 before ZEN4 does... right?
Quote:
In the case of ZEN4, just take off ZEN2, and it will automatically return back to the calling program...

I did not know that...
Yes, it will do that, since it ran out of code.
Alright, I removed the ZEN2 call out of ZEN4...


Now what do I do? lol...
Well, you are going to have to have it return back to the top of the program, correct?
Yep.. Was just about to post saying it's not doin' that...

Some of the places I call ZEN4 are inside of loops, so I can't use Goto AA...
Well, at the begining of an It Then/loop, have it Delvar /theta/ and then inside of ZEN4, at the end, have 1->/theta/. Then if /theta/=1, cancel out the loop (Guessing a While loop? Then change the value of the variable) and then outside the loop, have If /theta/=1:Goto AA

Under Lbl AA, have it restore the original value of the loop. Wink

Edit: You could also have it delvar /theta/ under the lbl as well... I just thought about that after I posted it...
Good God, Dan! Speak ENGLISH!
Sorry, I only know how to speak TI-BASIC Razz

Let me look at the code and prepare an example Wink
Thank you! Very Happy
Ok, take:

Quote:
:Lbl AA
:ClrHome
:Menu(Str0,"SWORD",1,"MAGIC",2,"STATS",3,"ITEMS",4,"RUN",5
:Lbl 1
:randInt(0,C)LMYS2(2)


And change to:

Quote:
:Lbl AA
:Delvar /theta/
:ClrHome
:Menu(Str0,"SWORD",1,"MAGIC",2,"STATS",3,"ITEMS",4,"RUN",5
:Lbl 1
:randInt(0,C)LMYS2(2)


Then, inside ZEN4, at the end of it, add 1->/theta/.

After any End statement that calls prgmZEN4, place if /theta/=1:Goto AA

Do you understand that? Try that out, see if that doesn't work for ya. Smile
Because there is no Then, is does not look for an End; therefore no problem with Goto. Nice. Wink

Quote:

:If LMYS2(1)5:Then
:" "Str2
:sub(Str1,1,T-1)+Str2+sub(Str1,T+1,length(Str1)-TStr1
:Return:End


Since Return is the last part of the program, I can take it out and it will still direct back to the same thing, right?
Do I keep the end or not?
All I need is a quick yes or no; just foolin' around with the syntax to see if things work.


I'm pretty sure it's that part that keeps lagging it up, for some reason...
After battle it doesn't seem to lag too much, but then I went over 5 blanks and then it started lagging; guess that means it's that part of the code.
[random comment: I've noticed people have been using my Lbl AA and Getkey-->K syntax a lot lately. Very Happy]
[Considering Dan and yourself taught me...]


Yea, that code is not quite causing the lag... it is something else.
I'll go post my current syntax...
prgmZEN1


BASIC Code wrote:
:randInt(1,10)LMYS2(1)
:If LMYS2(1)2:Then
:"Beaver"Str0
:{4,1,2,1,15,5}LMONST
:prgmZEN2:End
:If LMYS2(1)3 and LMYS2(1)4:Then
:"Rabbit"Str0
:{3,1,1,1,10,3}LMONST
:prgmZEN2:End
:If LMYS2(1)5:Then
:" "Str2
:sub(Str1,1,T-1)+Str2+sub(Str1,T+1,length(Str1)-TStr1
Generated by SourceCoder, © 2005 Cemetech



prgmZEN2:


BASIC Code wrote:
:Lbl AA
:DelVar Y
:ClrHome
:Menu(Str0,"SWORD",1,"MAGIC",2,"STATS",3,"ITEMS",4,"RUN",5
:Lbl 1
:randInt(0,C)LMYS2(2)
:ClrHome
:Output(1,1,"You deal"
:Output(1,10,LMYS2(2)
:Pause
:LMONST(1)-LMYS2(2)LMONST(1)
:If LMONST(1)0:Then
:prgmZEN3:End
:prgmZEN4
:If Y=1:Goto AA
:Lbl 2
:Menu("MAGIC","CURE",6,"Lightning",7,"Fire",8,"BACK",8
:Lbl 6
:ClrHome
:If B2:Then
:B-2B
:A+10A
:If A>E:Then
:Output(1,1,"You heal to fullHP!"
:Pause
:EA
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"You heal 10 HP"
:Pause
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"Not enough MP"
:Pause
:Goto AA
:Lbl 7
:ClrHome
:If B4:Then
:B-4B
:randInt(0,4)LMYS2(2)
:LMONST(1)-LMYS2(2)LMONST(1)
:Output(1,1,"You deal"
:Output(1,10,LMYS2(2)
:Pause
:If LMONST(1)0:Then
:prgmZEN3:End
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"Not enough MP"
:Pause
:Goto AA
:Lbl 8
:If B8:Then
:B-8B
:randInt(0,8)LMYS2(2)
:LMONST(1)-LMYS2(2)LMONST(1)
:Output(1,1,"You deal"
:Output(1,10,LMYS2(2)
:Pause
:If LMONST(1)0:Then
:prgmZEN3:End
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"Not enough MP"
:Pause
:Goto AA
:Lbl 9
:Goto AA
:Lbl 3
:ClrHome
:Output(1,1,"HP(-)"
:Output(1,6,A
:Output(1,9,"/"
:Output(1,12,E
:Output(2,1,"MP(-)"
:Output(2,6,B
:Output(2,9,"/"
:Output(2,12,F
:Output(3,1,"STR(-)"
:Output(3,6,C
:Output(4,1,"DEF(-)"
:Output(4,6,D
:Output(5,1,"EXP(-)"
:Output(5,6,N
:Output(5,9,"/"
:Output(5,12,Z
:Output(6,1,"Money(-)"
:Output(6,12,
:Pause
:Goto AA
:Lbl 4
:Menu("Items","Bread",10,"Honey Bread",11,"Red Potion",12,"Blue Potion",13)
:Lbl 10
:If LMYS2(10)>0:Then
:LMYS2(10)-1LMYS2(10)
:A+10A
:If A>E:Then
:Output(1,1,"You heal to fullHP!"
:Pause
:EA
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"You heal 10 HP"
:Pause
:prgmZEN4:End
:If Y=1:Goto AA
:ClrHome
:Output(1,1,"None."
:Pause
:Goto AA
:Lbl 11
:If LMYS2(11)>0:Then
:LMYS2(11)-1LMYS2(11)
:A+20A
:If A>E:Then
:Output(1,1,"You heal to fullHP!"
:Pause
:EA
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"You heal 20 HP"
:Pause
:prgmZEN4:End
:If Y=1:Goto AA
:ClrHome
:Output(1,1,"None."
:Pause
:Goto AA
:Lbl 12
:If LMYS2(12)>0:Then
:LMYS2(12)-1LMYS2(12)
:B+10B
:If B>F:Then
:Output(1,1,"You heal to fullMP!"
:Pause
:FB
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"You heal 10 MP"
:Pause
:prgmZEN4:End
:If Y=1:Goto AA
:ClrHome
:Output(1,1,"None."
:Pause
:Goto AA
:Lbl 13
:If LMYS2(13)>0:Then
:LMYS2(13)-1LMYS2(13)
:B+20B
:If B>F:Then
:Output(1,1,"You heal to fullMP!"
:Pause
:FB
:prgmZEN4:End
:If Y=1:Goto AA
:Output(1,1,"You heal 20 MP"
:Pause
:prgmZEN4:End
:If Y=1:Goto AA
:ClrHome
:Output(1,1,"None."
:Pause
:Goto AA
:Lbl 5
:randInt(1,4)LMYS2(3)
:If LMYS2(3)=1:Then
:ClrHome
:Output(1,1,"You ran away! (WIMP!)"
:Pause
:ClrHome
:prgmZTOWN1:prgmZGA:End
:If LMYS2(3)2:Then
:ClrHome
:Output(1,1,"You fail to run! (FAILURE!)"
:Pause
:ClrHome
:prgmZEN4:End
:If Y=1:Goto AA
Generated by SourceCoder, © 2005 Cemetech



prgmZEN3:


BASIC Code wrote:
:ClrHome
:Output(1,1,"You kill"
:Output(2,1,Str0
:Pause
:N+LMONST(5)N
:randInt(0,LMONST(6))LMYS2(8)
:+LMYS2(8)
:prgmZLVL:prgmZTOWN1:prgmZGA
Generated by SourceCoder, © 2005 Cemetech



prgmZEN4:


BASIC Code wrote:
:randInt(0,LMONST(3))LMYS2(7)
:ClrHome
:Output(1,1,Str0
:Output(2,1,"deals"
:Output(2,7,LMYS2(7)
:Pause
:A-LMYS2(7)A
:If A0:Then
:ClrHome
:Output(1,1,"You die..."
:Pause
:Stop:End
:1->Y
Generated by SourceCoder, © 2005 Cemetech



Any other ideas on the lag problem? *sigh*

Psst: Why does this SourceCoder cut off the last word of every file?
ZEN3 is not helping matters... You need to return back to the program that calls ZEN1, not just reload like it is doing so currently...
And how do you suppose I do that... *sigh*
  
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
» Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
» View previous topic :: View next topic  
Page 5 of 10
» 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