(S) How can I read certain lines of text from the C2 textbox

Get help using Construct 2

Post » Wed Feb 15, 2017 12:40 pm

(Solved)
Hey there!

I'm trying to make a coding/hacking game in the stile of TIS-100, but I don't know how to "read" certain lines that the player would type and how to make C2 recognize certain words (like "move" or "rotate") in order to assign them functions.

(Photo from TIS-100)
Image
In each square you can write a couple of commands, and the game executes them from top to bottom, but doesn't go to the next command until the current one has finished.

Any idea on how to do this?
Thanks!
Last edited by TRMG on Thu Feb 16, 2017 9:35 pm, edited 2 times in total.
ImageImageImageImage
B
30
S
9
G
7
Posts: 245
Reputation: 5,602

Post » Wed Feb 15, 2017 11:25 pm

bump...
ImageImageImageImage
B
30
S
9
G
7
Posts: 245
Reputation: 5,602

Post » Thu Feb 16, 2017 12:34 am

To get a certain line from some text you can use the tokenat() expression:
tokenat(TextBox.text, 0, newline)

The 0 means get the first line, 1 the second, and so on.

Beyond that you could use tokenat again to get individual words if you seperate everything with spaces or something. What that's called is a parser and there are also lots of other ways to do it. You could do a forum search for parser to see various examples to maybe get some ideas.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Thu Feb 16, 2017 2:34 pm

R0J0hound wrote:To get a certain line from some text you can use the tokenat() expression:
tokenat(TextBox.text, 0, newline)

The 0 means get the first line, 1 the second, and so on.

Beyond that you could use tokenat again to get individual words if you seperate everything with spaces or something. What that's called is a parser and there are also lots of other ways to do it. You could do a forum search for parser to see various examples to maybe get some ideas.

Awesome, thank you!
ImageImageImageImage
B
30
S
9
G
7
Posts: 245
Reputation: 5,602

Post » Fri Feb 17, 2017 11:28 pm

R0J0hound wrote:...Beyond that you could use tokenat again to get individual words if you seperate everything with spaces or something. What that's called is a parser and there are also lots of other ways to do it. You could do a forum search for parser to see various examples to maybe get some ideas.

Hey, I have searched for parser on the forum, but I haven't found anything about them...
Could you show me how to use tokenat for individual words?
ImageImageImageImage
B
30
S
9
G
7
Posts: 245
Reputation: 5,602

Post » Sat Feb 18, 2017 12:32 am

Here are the posts I was thinking of:
search.php?keywords=Parser&terms=all&author=R0j0hound&sc=1&sf=all&sr=posts&sk=t&sd=d&st=0&ch=300&t=0&submit=Search

Those ways give more control than tokenat, but the way to get indavidual words seperated by spaces is the same as the one to get lines except " " is used instead of newline.
I also know regex could possibly be used somehow.
B
92
S
32
G
109
Posts: 5,290
Reputation: 70,991

Post » Sat Feb 18, 2017 10:05 pm

R0J0hound wrote:Here are the posts I was thinking of:
search.php?keywords=Parser&terms=all&author=R0j0hound&sc=1&sf=all&sr=posts&sk=t&sd=d&st=0&ch=300&t=0&submit=Search

Those ways give more control than tokenat, but the way to get indavidual words seperated by spaces is the same as the one to get lines except " " is used instead of newline.
I also know regex could possibly be used somehow.

Great, thank you very much!
ImageImageImageImage
B
30
S
9
G
7
Posts: 245
Reputation: 5,602


Return to How do I....?

Who is online

Users browsing this forum: bclikesyou, kalibark2 and 34 guests