thankyou. I will definitely give you credit in the credits and readme.hart wrote:CompWiz, your code is pretty inefficient, so use this code instead. It should work for most cases, and it is relatively small and fast. Just remember to give credit. Also tell me if you find any problems with it.
Code: Select all
DelVar XDelVar Y While X<length(Str1 While sub(Str1,1,1)=" // 1 space sub(Str1,2,length(Str1)-1->Str1 End Repeat max(X={16,length(Str1 X+1->X If sub(Str1,X,1)=" // 1 space X->Y End Disp sub(Str1,1,min(Y(Y>12)+16(Y<=12),length(Str1 If X!=length(Str1 Then sub(Str1,Y(Y>12)+16(Y<=12)+1,length(Str1)-Y(Y>12)-16(Y<=12->Str1 DelVarXDelVar Y End:End
Adventure Game with text input
Moderator: MaxCoderz Staff
In Memory of the Maxcoderz Trophy
After looking at the code, I noticed an optimization that I forgot.
Code: Select all
DelVar XDelVar Y
While X<length(Str1
While sub(Str1,1,1)=" // 1 space
sub(Str1,2,length(Str1)-1->Str1
End
Repeat max(X={16,length(Str1
X+1->X
If sub(Str1,X,1)=" // 1 space
X->Y
End
16:If Y>12:Y
Disp sub(Str1,1,min(Ans,length(Str1
If X!=length(Str1
Then
sub(Str1,Ans+1,length(Str1)-Ans->Str1
DelVarXDelVar Y
End:End
I put some letters and spaces into string1, then ran your program. It started to work, then gave me the overflow error on this line:hart wrote:After looking at the code, I noticed an optimization that I forgot.
Code: Select all
DelVar XDelVar Y While X<length(Str1 While sub(Str1,1,1)=" // 1 space sub(Str1,2,length(Str1)-1->Str1 End Repeat max(X={16,length(Str1 X+1->X If sub(Str1,X,1)=" // 1 space X->Y End 16:If Y>12:Y Disp sub(Str1,1,min(Ans,length(Str1 If X!=length(Str1 Then sub(Str1,Ans+1,length(Str1)-Ans->Str1 DelVarXDelVar Y End:End
Code: Select all
If X!=length(Str1
In Memory of the Maxcoderz Trophy
-
- Calc Wizard
- Posts: 526
- Joined: Tue 08 Mar, 2005 1:37 am
- Location: who wants to know?
- Contact:
Code: Select all
Repeat X
While sub(Str1,1,1)=" // 1 space
sub(Str1,2,length(Str1)-1->Str1
End
1
While Ans and Ans<=min(16,length(Str1
Ans->Y
inString(Str1,Ans+1," //1 space
End
16<=length(Str1->X
16:If Y>12:Y
Disp sub(Str1,1,min(Ans,length(Str1
If not(X
sub(Str1,Ans+1,length(Str1)-Ans->Str1
End
Code: Select all
0
Repeat Ans=length(Str1
Ans+1->X
inString(Str1,"/",X
Disp sub(Str1,X,Ans-X
End
Oh, I forgot to change that. I'm not used to adapting tibasic to text and back. The =! just looked natural. I program C++ a lot.kalan_vod wrote:I hope you know it means not equal to (!=) so you need to change it to the equal sign with the slash through it.[/code]
Thanks for the suggestion, but this won't work the way the game will be set up. Thank you for working on it thoughDarkerLine wrote:There's also another alternative. If the strings were formatted so that the "/" symbol signified a line break (this won't cause an increase in size because spaces were line breaks before), you could use the following (shorter) code:
Code:
0
Repeat Ans=length(Str1
Ans+1->X
inString(Str1,"/",X
Disp sub(Str1,X,Ans-X
End
An example string would be "THIS SENTENCE/WRAPS ACROSS/SEVERAL LINES/". Of course, if you replace the "/" symbol with another symbol, you can use another symbol, just choose something that won't occur in the string naturally.
In Memory of the Maxcoderz Trophy
What is the best way to put a bunch of numbers into a matrix? I need to fill a 20x6 matrix with numbers when the game is first started as a pre-load. Would it be best to put something like:
Or would it be better to have the program take one huge number that is all of the numbers that need to go in the matrix, in order, and have a loop pull each digit off and put it into the matrix, one at a time.
(I know this code isn't done. Don't correct it. Just showing my concept. Thanks )
While it would be smaller, I fear that might take too long unfortunately. This operation cannot take too long, as it needs to run when the program starts, without too much delay. In case it would help, most of the digits are 0. Does anyone have a suggestion on how to do this?
Code: Select all
List>matr({4,3,2,0,0,0},{0,0,0,1,0,0},{1,0,0,0,0,0},{0,1,0,5,0,0},(more until matrix is full), [A])
Code: Select all
1->b
432000000100100000010500->x
while(x>0)
a+1->a
if(a>6)
then
b+1->b
1->a
End
x-(int(x/10))*10->[A](a,b)
int(x/10)->x
End
While it would be smaller, I fear that might take too long unfortunately. This operation cannot take too long, as it needs to run when the program starts, without too much delay. In case it would help, most of the digits are 0. Does anyone have a suggestion on how to do this?
In Memory of the Maxcoderz Trophy
Ok due to the limits of basic or just the calc itself, once you have a # larger than 13 it will not work, what I mean is I can get it to return the part of the # that I want, but when the part I need is greater than the 13th postition it returns a zero atoumatically.
Edit:
On anouther note you could use a compression techniqe where you list how many of the number proceeds I.E. 12,0 means 12 of sprite 0.
Btw if this did work or will work how would you make it use sprites larger than 9?
When you run this it returns X in reverse order.BASIC Code wrote::ClrHome
:1234567890123X
:For(,1,int(log(X)+1
/10X
-int(X
:Pause int(Ans*10
:End
Edit:
On anouther note you could use a compression techniqe where you list how many of the number proceeds I.E. 12,0 means 12 of sprite 0.
Btw if this did work or will work how would you make it use sprites larger than 9?
Yeah, now that I think about it, I will have to use numbers higher than 9. (however, I need only a couple of those) So, would the best, fastest way be to just write out the lists and put them into the maxtrix, like:
Code: Select all
List>matr({4,3,2,0,0,0},{0,0,0,1,0,0},{1,0,0,0,0,0},{0,1,0,5,0,0},(more until matrix is full), [A])
In Memory of the Maxcoderz Trophy