joshie75 wrote:
so basically that little code right there set the dimension to 26 spaces.. and then it assigned each space a number.. and to recall the letter B lets say.. ill use..
:LALPHA(2
?


Exactly. Very Happy
The List has 1-26, as does the alphabet and the string.
I will explain how sub() works in general, it is a very nice and simple concept.

Elements of a sub():
sub(StrX,1,2


sub() is taking a part of a string, specified by the first element in sub()
The second, which is the 1 above, is telling it where in the string to start, so a 1 is the beginning of the string, while a 2 is the second character in it, 3 is 3rd, and so on.
The last element, 2 in the elements of a sub() in bold, is how long of the string you want, it cannot exceed the length of the string-the first element, as it is non-existent, so a 1 would return 1 element from the specified location, defined by the number in front of it.

If that doesn't make sense, please let me know, I am more then happy to help you figure this out.
so if i used...
sub(str1,3,6
it would take the 3rd,4th,5th,and 6th spot out? is my understanding correct?
joshie75 wrote:
so if i used...
sub(str1,3,6
it would take the 3rd,4th,5th,and 6th spot out? is my understanding correct?


Very close, think of it this way, add the second number to the first, and you will get those spots, since number 1 is a 3, and 2 is a 6, you get the 3rd, 4th, 5th, 6th, 7th, and 8th spots, because that will be 6 spaces after the first number.
oh i gotcha Very Happy
wouldn't you get the 9th too?
joshie75 wrote:
oh i gotcha Very Happy
wouldn't you get the 9th too?


That was a flaw in my explanation, just think of it as the first number as the first one you get if you have more then one, just like this:


Code:
:"ABCDEFG->Str1
:sub(Str1,1,1


Would give this: A


Code:
:"ABCDEFG->Str1
:sub(Str1,1,4


Would give this: ABCD


Code:
:"ABCDEFG->Str1
:sub(Str1,3,1


While this would give: C

Does all that make sense?
oh so the first part tells where to start.. the second part tells how many to grab, including the starting point
joshie75 wrote:
oh so the first part tells where to start.. the second part tells how many to grab, including the starting point


EXACTLY, I wish I thought of that when I was explaining, I tend to not be too great at explaining things, but I thought I would give it a go to try and help someone who I can(which is very rare as I am relatively new still).
sweet, Very Happy
to be honest i like your explanations the best because your mind thinks like mine does since your relatively new. The better programmers use harder to understand codes and terms to describe it. thanks for all the help tho, i hope im not a nuisance Razz
so now that i have all the knowledge i need about sub()..
how would i use that toward my program. i should first store the alphabet as str3.. then when they input a letter, lets say E..

:sub(str3,5,1

i know that's E... but if im displaying str3 through Text(X,Y,Str3...
how can i make it lets say put a "" where the e was in the string to show the player has already picked that letter?
joshie75 wrote:
sweet, Very Happy
to be honest i like your explanations the best because your mind thinks like mine does since your relatively new. The better programmers use harder to understand codes and terms to describe it. thanks for all the help tho, i hope im not a nuisance Razz
so now that i have all the knowledge i need about sub()..
how would i use that toward my program. i should first store the alphabet as str3.. then when they input a letter, lets say E..

:sub(str3,5,1

i know that's E... but if im displaying str3 through Text(X,Y,Str3...
how can i make it lets say put a "" where the e was in the string to show the player has already picked that letter?


That is relatively simple to be honest, but I am going to have to explain it tomorrow. :/
joshie75 wrote:
so basically that little code right there set the dimension to 26 spaces.. and then it assigned each space a number.. and to recall the letter B lets say.. ill use..
:LALPHA(2
?
Keep in mind that you can only store numbers in lists, so all you'll get out is something representing letters, for example number 1-26 representing "A" through "Z".
KermMartian wrote:
joshie75 wrote:
so basically that little code right there set the dimension to 26 spaces.. and then it assigned each space a number.. and to recall the letter B lets say.. ill use..
:LALPHA(2
?
Keep in mind that you can only store numbers in lists, so all you'll get out is something representing letters, for example number 1-26 representing "A" through "Z".

I completely forgot to mention that. >.<
joshie75 wrote:
sweet, Very Happy
to be honest i like your explanations the best because your mind thinks like mine does since your relatively new. The better programmers use harder to understand codes and terms to describe it. thanks for all the help tho, i hope im not a nuisance Razz
so now that i have all the knowledge i need about sub()..
how would i use that toward my program. i should first store the alphabet as str3.. then when they input a letter, lets say E..


Code:
:sub(str3,5,1


i know that's E... but if im displaying str3 through Text(X,Y,Str3...
how can i make it lets say put a "" where the e was in the string to show the player has already picked that letter?
You could do something like this. Say that the number of the letter picked is in X (in the E example, X=5, right?). Then you could do this:


Code:
:sub(Str3,1,4)+"/"+sub(Str3,6,26-6+1)->Str3


or in other words


Code:
:sub(Str3,1,X-1)+"/"+sub(Str3,X+1,26-(X+1)+1)->Str3


which is the same as


Code:
:sub(Str3,1,X-1)+"/"+sub(Str3,X+1,26-X)->Str3


The first sub picks out "ABCD", while the second picks out "FGH...Z". The '+' concatenates the two strings (merges them) and the ->Str3 obviously stores them. There will be a problem with removing the first letter, "A", or 1, though, because it would be like this:


Code:
:sub(Str3,1,1-1)+"/"+sub(Str3,1+1,26-1)->Str3


You can't take a sub() of zero-length; you'll get an error. Similarly, there will be a problem with removing Z (26):


Code:
:sub(Str3,1,26-1)+"/"+sub(Str3,26+1,26-26)->Str3


Now we're not only taking a sub() of zero length, we're taking a string starting at character 27, which our string does not have. Therefore, we need special cases for when X=1 and X=26. What we can do is pad Str3 with an extra character on the front and back, do the removal, and then remove the padding characters. If we add padding, we'll be at most removing the second or second-to-last characters, so we won't have to deal with special cases:


Code:
:"/"+Str3+"/"->Str3 //Add the padding
:sub(Str3,2,X-1+1)+"/"+sub(Str3,X+1+1,26-X+1)->Str3
:sub(Str3,2,26)->Str3 //Remove the padding


On the second line, notice that everything has been incremented by 1 to deal with the fact that now we have an extra character at the front, so A (1) is actually the second character, B is the third, etc. We can clean up and optimize that code a bit:


Code:
:"/"+Str3+"/->Str3 //Add the padding
:sub(Str3,2,X)+"/"+sub(Str3,X+2,27-X->Str3
:sub(Str3,2,26->Str3 //Remove the padding


I hope that makes sense. However, I recommend a different strategy. I think you should start out Str3 as a simple string with an illegal (ie, not a letter, so the user can't guess it) character:


Code:
"/"->Str3


Then, as the user guesses letters, you can append them to the string. Say the letter the user guessed is in Str4:


Code:
Str3+Str4->Str3


If the user guesses "E", then Str3 will become "/E". If he or she then guesses "S", Str3 will become "/ES". The fun part is detecting whether this letter has already been guessed:


Code:
If inString(Str3,Str4
Then
Disp "ALREADY GUESSED!
Else
Str3+Str4->Str3
End


See how easy? Smile
now when you use...

Code:

Code:
:"/"+Str3+"/->Str3 //Add the padding
:sub(Str3,2,X)+"/"+sub(Str3,X+2,27-X->Str3
:sub(Str3,2,26->Str3 //Remove the padding


that first line where it does "/"+Str3+"/->Str3
what exactly does that part do?
i know that the second line restates the string up until the point being changed.. then changes the one point, then restates the rest, correct?
and the last line just returns my str to normal.. correct?
A protip: Use [ code] and [ /code] tags (without the spaces) around your code for better formatting. Also, I haven't picked on you much for the lack of capital letters, but they would be appreciated. Wink

The first line: Adds a one-character pad to the front and back of the string so that we'll never have to replace the first or last character (only the 2nd through 27th of the new 28-character string).
The second line: Performs the replacement
The third line: Removes the padding
So far my hangman works great. It does mostly everything i want it to and im proud of where i've gotten with it because its my first kinda functioning game lol. The problem I'm having now is that the Alphabet displayed on my graph screen... for each letter.. is to be replaced by a "/" to show it has been picked. but instead of replacing it, it seems to just pushing everything to the left kind of.. ex:

"ABCDEFG"
the person picks D lets say, the graph screen would show this;
"BCD/EFG"
at least that's how it looks to me :S please test it out for a few guesses to know what i mean if you can.
here is my Code:


Code:

:0->G
:0->R
:"ABCDEFGHIJKLMNOPQRSTUVWXYZ"->Str3
:ClrHome
:ClrDraw
:AxesOff
:Input "Your word please",Str1
:length(Str1)->L
:Text(1,1,"Number of letters"
:Text(8,1,L
:Pause
:Lbl 1
:ClrHome
:Input "pick one letter ",Str2
:Repeat Z=0
:inString(Str3,Str2)->H
:inString(Str1,Str2,N)->Z
:If Z>0
:R+1->R
:Text(16,1,"Number of letters in word"
:Text(24,1,R
:Z+1->N
:End
:"/"+Str3+"/"->Str3
:sub(Str3,2,H)+"/"+sub(Str3,H+2,27-H->Str3
:sub(Str3,2,26)->Str3
:0->R
:1->N
:1->Z
:Text(40,40,sub(Str3,1,13
:Text(50,40,sub(Str3,14,13
:Line(-8,-9,-3,-9
:Line(-4,-9,-4,0
:Line(-4,0,-7,0
:Line(-7,0,-7,-2
:Pause
:Goto 1
Hehe, I see I made a slight error, sorry about that:


Code:
:sub(Str3,2,H)+"/"+sub(Str3,H+2,27-H->Str3


should be


Code:
:sub(Str3,1,H)+"/"+sub(Str3,H+2,27-H->Str3
Weregoose pointed that out. Thanks for the help Smile i'll probably be back for more help on this game soon enough, for next i get to make the part where if the letter is not in the word then you add a body part >Smile
From the knowledge I have about programing so far, I should be able to do this part by myself, but who knows Razz
Sounds good, good luck with it. Don't be a hero, though; there's no point banging your head against something for a long time when there's people willing to help. Smile
Alright, my program is coming to and end here, but to wrap up this program i need to add 2 features and fix one feature an then it should be done.. Wink
1) If the letter is already guessed.
2) You know in elementary school how you used to grab sheet of paper and you would draw how many lines were in the word? say your word was Paper. You would write _ _ _ _ _... I would like to use this instead of what i started with where i have "Number of letters".. i want to keep those words there, but where i have the length of the string displayed, thats where i would like the liens to go. Any thoughts?
3) When you lose, the screen it takes you to has a frowny face and an option to play again "yes or no" and has a getkey command. But when it gets to that screen it gives you no time to chose and automatically assumes you pick no, help Sad
and as for the letter already being guessed.. you gave me a code for your illegal string path, but what i cant figure out is how to make it work with my already almost complete code. Thanks in advance Smile here is my code. (and yes Kerm, i know i suck at capital letters, im just so darned lazy, but i promise you over time ill work on it) :)Here's my code..

Code:

Code:

:Lbl 5
:0->W
:0->G
:0->R
:"ABCDEFGHIJKLMNOPQRSTUVWXYZ"->Str3
:ClrHome
:ClrDraw
:AxesOff
:Input "Your word please",Str1
:length(Str1)->L
:Text(1,1,"Number of letters"
:Text(8,1,L
:Pause
:Lbl 1
:ClrHome
:Input "pick one letter ",Str2
:Repeat Z=0
:inString(Str3,Str2)->H
:inString(Str1,Str2,N)->Z
:inString(Str1,Str2)->F
:If F=0
:Goto 2
:If Z>0
:R+1->R
:Lbl 3
:If W=6
:Goto 4
:Text(16,1,"Number of letters in word"
:Text(24,1,R
:Z+1->N
:"/"+Str3+"/"->Str3
:sub(Str3,2,H)+"/"+sub(Str3,H+2,27-H->Str3
:sub(Str3,2,26)->Str3
:0->R
:1->N
:1->Z
:Text(40,40,sub(Str3,1,13
:Text(50,40,sub(Str3,14,13
:Line(-8,-9,-3,-9
:Line(-4,-9,-4,0
:Line(-4,0,-7,0
:Line(-7,0,-7,-2
:Pause
:Goto 1
:Lbl 2
:W+1->W
:If W=1
:Circle(-7,-3,1
:If W=2
:Line(-7,-4,-7,-7
:If W=3
:Line(-7,-7,-7.5,-8
:If W=4
:Line(-7,-7,-6.5,-8
:If W=5
:Line(-7,-5,-7.5,-6
:If W=6
:Line(-7,-5,-6.5,-6
:End
:Pause
:Goto 3
:Lbl 4
:ClrHome
:ClrDraw
:Circle(0,0,4
:Text(5,25,"You have lost"
:Text(26,40,"X
:Text(26,52,"X
:Text(45,28,"Play again?"
:Text(53,16,"Yes"
:Text(53,70,"No"
:Line(0,-1,-1,-2
:Line(0,-1,1,-2
:If K=12
:Goto 5
:If K=14
:ClrHome
:Output(3,5,"Made by"
:Output(5,2,"Josh Beckwith"
How about replacing
Code:
:length(Str1)->L
:Text(1,1,"Number of letters"
:Text(8,1,L
with
Code:
:"-
:For(L,2,length(Str1
:Ans+"-
:End
:Text(8,1,Ans
  
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