Text Box questions

Just started using Construct 2? Post your questions here

Post » Sat Apr 11, 2015 10:05 am

I'm trying to make a fake translator, similar to google translate's layout.
Regardless to what the player writes, the game counts the number of words in the textbox and gives as "translation" the same number of words by picking random words from a database.

I've read the textbox guide but it's still beyond my comprehension. I wonder why it uses something as complex as CSS instead of being user friendly like the rest of Construct 2.

I'd need:
-to center the text top-left (I could center it horizontally with the "align" CSS command, but vertically it's always in the middle of the box)
-to know the number of words written by the player in a textbox (words, not letters)
-put automatic line breaks if the text exceeds the box's width while the player is writing


Thank you in advance for your help and sorry, but I'm a total noob at this...
B
8
S
1
Posts: 20
Reputation: 490

Post » Sat Apr 11, 2015 1:11 pm

1) use textarea as type
2) loop through the text character by character, count words by logic like: stop counting as word when punctuation, newline or space follows, start counting a word when a character unlike punctuation etc appears.
3) textarea does that automatically
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Sat Apr 11, 2015 9:48 pm

Thanks a lot! I knew it was easier than I thought!

Could you please help me on how to exactly tell construct to count the number of " " (empty spaces) in a sentence?
I tried to count the number of times the player presses the spacebar, but they only get counted while he isn't typing in the textbox!
B
8
S
1
Posts: 20
Reputation: 490

Post » Sat Apr 11, 2015 10:16 pm

WadaKatsu wrote: how to tell construct to count the number of " " (empty spaces) in a sentence?

...just a thought

capx:
http://s000.tinyupload.com/index.php?fi ... 8500618191
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Sun Apr 12, 2015 9:59 am

korbaach wrote:
WadaKatsu wrote: how to tell construct to count the number of " " (empty spaces) in a sentence?

...just a thought

capx:
http://s000.tinyupload.com/index.php?fi ... 8500618191

That's great but I honestly can't understand what you did... I still have to learn about AJAX and Arrays, Ashley's guides about them are a bit too complex for a total noob like me...
Could you please exactly point out to me which event counts the number of empty spaces?

I'm sorry for the silly questions but you see, I still have to get a grasp of this...
B
8
S
1
Posts: 20
Reputation: 490

Post » Sun Apr 12, 2015 10:34 am

TypeBox compare text.............trim(aTypeBox.Text)&" "

so..let's say your:
TypeBox Text= is "WORD(blank space) "
..then
trim(TypeBox.Text) will be just "WORD"
.. and
trim(TypeBox.Text)&" " wil be "WORD"& "(blank space) "

...now you know you have blank space affter "WORD" :D


EDIT:
anyway......... @WadaKatsu forget it :D

for counting words you need something like this...

capx:
http://s000.tinyupload.com/index.php?fi ... 0273882192

WadaKatsu wrote: I still have to learn about AJAX and Arrays...


..now you can add Regular Expressions to list... :)

good starting point ... http://www.regexr.com/
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest