Writing a sentence with a typing machine

This forum is meant for requesting technical support or reporting bugs.

Moderators: time-killer-games, Vengeance66, Candle, reneuend, GM-Support

Writing a sentence with a typing machine

Postby marina » Tue Nov 22, 2011 12:40 pm

Hi everybody!
A very long time passed since my last visit, and I gratefully remember all the help I received in the forums. :D
I had to give up going on with my game for ages but now I?d like to give it a chance again.

I?m here with a question. I have a typing machine and want the player to type a sentence of five words. I almost forgot all that I learnt on codes, but I fancied that if I associated a variable to each correct key pressed I could use an If statement to make the player proceed word after word.
I?ll try to explain: some letters as ?A? or ?I? are repeated in the sentence, so I made four copies of the frame ?Typewriter? with the typing machine, to change, word after word, the association to the variables on the same keys.
The first word has four letters, and to each of them I associated a variable: uno, due, tre, quattro; pressing the right keys (no matter the order, it makes sense only in one order) those four variables would change their value as 1.
Then I wrote a code as such in the window of VBScript Global Procedures:

If uno = 1 and due = 1 and tre = 1 and quattro = 1 Then
Action.GoToFrame "Typewriter 2"
End If

Then I made the same steps for the following words, until the last, after which the player would go to a different frame and understand that the sentence was correct.
But it doesn?t work? the frames don?t change, I remain in the first frame "Typewriter" all the time. Would someone please help me understand what?s wrong? My code looks like that:

If uno = 1 and due = 1 and tre = 1 and quattro = 1 Then
Action.GoToFrame "Typewriter 2"
End If

If cinque = 1 and sei = 1 Then
Action.GoToFrame " Typewriter 3"
End If

If sette = 1 and otto = 1 and nove = 1 and dieci = 1 and undici = 1 and dodici = 1 Then
Action.GoToFrame " Typewriter 4"
End If

If tredici = 1 and quattordici = 1 Then
Action.GoToFrame " Typewriter 5"
End If

If h1 = 1 and h2 = 1 and h3 = 1 and h4 = 1 and h5 = 1 and h6 = 1 and h7 = 1 and h8 = 1 and h9 = 1 Then
Action.GoToFrame "CHIAVE"
End If

Thanks a lot! :)
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby reneuend » Tue Nov 22, 2011 3:12 pm

UPDATED CODE!!!

Wow! It has been a long time. Welcome back! :)

I don't think your code is getting called. Each hotspot would have to check to see if a word or sentence was done by calling the procedure.

There is a more efficient way to do this. In fact, why not check after each keypress to see if the WHOLE sentence is done!

This is very much the same process as the sequence puzzles I've been showing users how to build.

In your case, it is very much like the AM_Journal plugin that 3DGamer and I built a few years ago, except we didn't make it a puzzle, just a note taker.

Image

To keep it simple I would suggest using an textbox. a typewriter image with a hotspot on each letter key.

You'll have to track the number of key-presses made. You would add the same counter variable to each hotspot and just add up like this:
Code: Select all
KeyCount = KeyCount + 1


After this line, you would check to see if the user has gone beyond the puzzle's answer. Let's say the answer is "Mary had a little lamb". That is 22 characters including spaces. Be sure to have a space bar on your typewriter. So, then you would check to see if KeyCount > 22. Notice that I used a variable, Answer, to hold the string, "mary had a little lamb", and that I check the length of the Answer in the code using len(Answer) instead of hard-coding a 22. This is so you can change the Answer to whatever phrase you want creating a brand new puzzle by simply changing the value for Answer, and by using len(Answer), the code will NOT have to be updated with the number of characters in the answer.

Code: Select all
KeyCount = KeyCount + 1

Text(1).caption = Text(1).caption & "q"  'If this is the "M-key" hotspot

If KeyCount > len(Answer) Then
    keyCount = 0
    Text(1).caption = ""
    Action.Message "You pull the paper from the typewriter and start over"
ElseIf KeyCount = len(Answer) Then
    If Text(1).caption = Answer Then
        'SUCCESS!!!!!
        Action.GoToFrame "success"
    End If
End If


To make this easier to add a hotspot to every key, just create the first button, 'q' (on a qwerty typewriter), and duplicate the hotspot. Then just change the letter that gets added to the text(1).caption in the second statement.

In the frame properties, add the following to reset the puzzle:
Code: Select all
Answer = "mary had a little lamb"
KeyCount = 0
Text(1).caption = ""


Be sure to add the variables under "Advanced-Variables":
KeyCount as integer
Answer as variant
Last edited by reneuend on Wed Nov 23, 2011 2:50 pm, edited 3 times in total.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby marina » Tue Nov 22, 2011 3:34 pm

Wow Reneuend! After all this time you remember me... Thanks for both, help and welcome!!!
I'm glad to meet you again :D

Now I understand why the code didn't work properly. I copied your post and I'll study it thoroughly tonight. I'll be back soon with news, hopefully good.

Thanks an awful lot, have a beautiful day!
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby reneuend » Tue Nov 22, 2011 3:50 pm

Yep! I remember you. You had some great posts. :wink:

Please don't give up on your project. If you get stuck, just ping the forums or PM me.

I'd like to see everyone finish their projects and I'm willing to help where I can. The more projects finished, the better people get at building games, the more active they become, and the more active these forums get, and ultimately, the better chance GM will want to improve Adventure Maker.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby reneuend » Tue Nov 22, 2011 4:06 pm

I updated the code.

I found a mistake. I removed the "else" statement that displayed the character for the keypress and added it at the top of the code (second statement). I should have tested this before posting! :oops:
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby marina » Tue Nov 22, 2011 4:47 pm

I'd never think that any of my posts could be great, I just remember having had exchanges with beautiful and helpful people... wow... 8)

Don't worry about the code Reneuend, I didn't try to implement it yet. Thanks a lot for the update!

Be sure that I have no intention to give up on my project(s), I love too much the idea of creating games as well as playing them!
Thanks for your nice help offer, I'm afraid I'll have more questions for you. :oops:

Hear from me soon :D
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby marina » Wed Nov 23, 2011 9:41 am

Good morning Reneuend, whatever time it is in your country :D

I'm afraid that all the time I've been away from my beloved AM has a bit... frozen my braincells... :oops:
I've got some stupid questions I'm ashamed of, but that's it.

Let's say that my sentence is "Mary had had a little lamb" and has 22 charachters including spaces (never know, maybe one day you'll play my game :wink: )

Seen that in your code for the frame properties you wrote Answer = "mary had a little lamb", I assume that the variant variable to add should be called just "Answer", or what I like, but not "mary had a little lamb". So I created an integer called "KeyCount" (in the code for the frame properties you wrote "KeyCounter", is that an error or you meant it to be like that?) and a variant called "Answer", obviously without quotes.
I already have duplicated hotspots for each key and the spacebar, each sending to frames with the graphic effect for pressing and back, and for all of them I changed the letter in the string "Text(1).caption = Text(1).caption & (letter).
What I don't understand is what I should write between the quotes and what "len(Answer)" means...

I wonder if you could be so patient to complete the codes exactly as you would write them for the sentence "Mary had a little lamb" with its 22 characters, so I'd write them as they are just changing the words and the number of characters.
Sorry for being so dumb and for wasting your time, and...
Thanks a LOT for your help! :)
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby reneuend » Wed Nov 23, 2011 2:15 pm

Gasp! KeyCounter was incorrect. It should have been KeyCount.

There are only 2 variables: KeyCount, Answer

"mary had a little lamb" is the value assigned to the variable, Answer

len( ) returns the length of a string.

So, I'm using it to find the length of the value for the variable, Answer.
Since "mary had a little lamb" is 22 characters, len(Answer) will return 22.
The reason I'm NOT just putting in 22 is because I want the user to be able to set Answer to any string value they want. So, lets say you want the answer to be, "I love to code". By using len(Answer), I don't have to go through all the hotspots and change 22 to 14. It will return the length of the string for me no matter what size it is.

I hope that helps! Let me know if you need more help!
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby ShadowHunter » Wed Nov 23, 2011 3:25 pm

Hi,

Why not use the tag of the hotspot to hold its letter and built op the string using one global variable?

Next compare the append variable with the wanted word or phraze?

That way, with minimal coding a very easy to add words routine is written.

Hotspot(1).tag = "A"
hotspot(2).tag = "B"
...

Each hotspot click pass the tag to the routine and compare:

ProcessHotSpotClick(TagValue)
GlobalVar = GlobalVar & TagValue
if GlobalVar = "This word" Then dostuff
End

Good luck,

With best regards,

ShAdOwHuNtEr
User avatar
ShadowHunter
Forum Admin and Games Page admin
 
Posts: 1304
Joined: Fri Jun 06, 2003 10:37 pm
Location: Belgium

Postby reneuend » Wed Nov 23, 2011 3:35 pm

Very clever! I forgot about the hotspot tags!
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby ShadowHunter » Wed Nov 23, 2011 3:46 pm

Thanks :D
User avatar
ShadowHunter
Forum Admin and Games Page admin
 
Posts: 1304
Joined: Fri Jun 06, 2003 10:37 pm
Location: Belgium

Postby marina » Wed Nov 23, 2011 6:44 pm

Thanks a lot to you both!
So nice to meet you again ShadowHunter! :D

It's been a hard working day :shock: but I think I grasped it finally!
I'll make my try tomorrow morning, when my head will be clearer :roll:

Have a beautiful evening, I'll let you know :D
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby reneuend » Wed Nov 23, 2011 6:47 pm

I'm writing up an example using ShadowHunter's information. I'll post it soon.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby ShadowHunter » Wed Nov 23, 2011 7:02 pm

Nice seeing you again as well :D

A few weeks ago I was in Rome... that day when it rained so hard and there was thunder and lightning all day along...

Still, had some great pizza in "Gallo Rosso" with tons of Grappa, Averna and Limocello :wink:

I'm sure Reneuend will write a great piece of code for you.

Good luck,

With best regards,

ShAdOwHuNtEr
User avatar
ShadowHunter
Forum Admin and Games Page admin
 
Posts: 1304
Joined: Fri Jun 06, 2003 10:37 pm
Location: Belgium

Postby reneuend » Wed Nov 23, 2011 7:11 pm

reneuend wrote:
From Shadow's Response:

Using the hotspot().tag method we can store the keypress character in the hotspot's tag. Why? What is the advantage?

The biggest advantage is that it makes the hotspots all the same. So, any changes that need to be done can be done in 1 place and not in every hotspot. It also removes the need for a counter!

Image

I'm still using a textbox. a typewriter image with a hotspot on each letter key.

Each hotspot will have the following code in the advanced tab:

Code: Select all
ProcessHotSpotClick(Action.GetHotspotNumber)



This calls the ProcessHotSpotClick routine and passes the hotspot number to that routine.


Click on the [procedures...] button and add this routine:

Code: Select all
sub ProcessHotSpotClick(tagvalue)

   Dim hsvalue

   hsvalue = Hotspot(tagvalue).tag
   Text(1).caption = Text(1).caption & hsvalue

   If Text(1).caption = Answer Then
      'Success
      Action.GoToFrame "success"
   ElseIf len(text(1).caption) = len(Answer) Then
      'fail!
      Action.message "Rats! You pull the paper from the typewriter," & vbcrlf & "crumple it, and start over."
      Text(1).caption = ""
   Else
      'do nothing
   End If

End Sub


You probably would change the message or the action that should happen when the player gets the correct answer, but that is about all. Plus, since the routine is in one place, you can affect all of the hotspots in this routine. For instance, i could add a click sound to the "Else" statement.

Finally, Add the following code to set up the tags in the Frames Properties - Advanced Tab:

Code: Select all
Answer = "test"
Text(1).caption = ""

Hotspot(2).tag = "q"
Hotspot(3).tag = "w"
Hotspot(4).tag = "e"
Hotspot(5).tag = "r"
Hotspot(6).tag = "t"
Hotspot(7).tag = "y"
Hotspot(8).tag = "u"
Hotspot(9).tag = "i"
Hotspot(10).tag = "o"
Hotspot(11).tag = "p"
Hotspot(12).tag = "a"
Hotspot(13).tag = "s"
Hotspot(14).tag = "d"
Hotspot(15).tag = "f"
Hotspot(16).tag = "g"
Hotspot(17).tag = "h"
Hotspot(18).tag = "j"
Hotspot(19).tag = "k"
Hotspot(20).tag = "l"
Hotspot(21).tag = "z"
Hotspot(22).tag = "x"
Hotspot(23).tag = "c"
Hotspot(24).tag = "v"
Hotspot(25).tag = "b"
Hotspot(26).tag = "n"
Hotspot(27).tag = "m"
Hotspot(28).tag = " "


Change the value for the variable, Answer to the value you want the player to solve.

Be sure to add this 1 variable under "Advanced-Variables":
Answer as variant
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby marina » Wed Nov 23, 2011 7:33 pm

Wow!!!
Thanks a lot again :D
I'm sure as well Reneuend's is a great piece of code for me! I'll know tomorrow morning, now I'm about to go to sleep 8)

You know, ShadowHunter, the "Gallo rosso" is quite far from my home; if you have been near "San Giovanni", you missed me for a handful of meters.
I'm fond of grappa! Next time you come to Rome send me a message! :lol:
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby ShadowHunter » Wed Nov 23, 2011 8:54 pm

marina wrote:Wow!!!
Thanks a lot again :D
I'm sure as well Reneuend's is a great piece of code for me! I'll know tomorrow morning, now I'm about to go to sleep 8)

You know, ShadowHunter, the "Gallo rosso" is quite far from my home; if you have been near "San Giovanni", you missed me for a handful of meters.
I'm fond of grappa! Next time you come to Rome send me a message! :lol:


Unfortunattely I'm always in Rome for business (one or two times per year) and only see the inside of a taxi, hotel or meeting room so visiting the "Gallo Rosso" was quite a nice change for once... I drove 20 times by the Colloseum but never had the change to visit it :(

I'll let you know next time, perhaps you can give me some touristic advice :D

Very nice code Renuend... beautifull.

Succes,

ShAdOwHuNtEr
User avatar
ShadowHunter
Forum Admin and Games Page admin
 
Posts: 1304
Joined: Fri Jun 06, 2003 10:37 pm
Location: Belgium

Postby marina » Thu Nov 24, 2011 7:05 am

Wowwwww!!!! Success!!!! :D :D :D
A million thanks to you both for using your time and patience in helping me!!!
Reneuend, I'll never thank you enough for writing the entire code for me!
You know, I liked a lot your failure message... pity that most Italian players wouldn't understand and the translation doesn't sound as much amusing :lol:

It didn't work at once, so I thought that the brief passage to the frames with the graphic effect of the key being pressed could prevent it from working, and it was true. As I disabled the transition to another frame it worked perfectly.
Now I have to study another way of showing the effect. I'd rather not using sound or lowering of the key, I liked the idea of enlightening the key pressed for an instant.

Here's what I mean... I love that old typewriter that belonged to my mother.

Thanks again! Have a great day :)

@ ShadowHunter, I honestly think that you didn't loose much not visiting the colloseum; in Rome there are much better ancient places to visit. I'm at your disposal for touristic advice :D
Attachments
CECCHINA G.jpg
CECCHINA G.jpg (75.66 KiB) Viewed 6886 times
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome

Postby reneuend » Thu Nov 24, 2011 7:17 am

I'm glad you got it to work. :D

Yep! I didn't make it global that's why it didn't work. If you define the variables globally, I think that's all you need. You do that from the Project properties.

it's 1am here...off to bed.
---


Image
Image
User avatar
reneuend
Administrator
 
Posts: 2762
Joined: Sat Nov 22, 2008 8:37 pm
Location: Midwest Cornfield, USA

Postby marina » Thu Nov 24, 2011 7:27 am

I'll try to do it and I'll let you know, thanks!
Here it's 7 am, I got up at 4 to try the code.

Have a nice, resting sleep Reneuend! :)
I'm fond of Rhem-like games!
User avatar
marina
Member
 
Posts: 44
Joined: Sun Nov 23, 2008 8:27 pm
Location: Rome


Return to Adventure Maker Technical Support and Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

cron