How do I send a /pm in Chat Box

Get help using Construct 2

Post » Wed Oct 19, 2016 6:47 am

I'm following this tutorial: https://www.scirra.com/tutorials/906/mu ... e-5?page=1

In the conclusion it says: 'If you feel like a challenge, try coming up with a way to private message individual peers in the chat room.'

This is usually done with /pm or /whisper in most of the games I've played, the only problem is I don't know how to set this up. Obviously it's telling me to figure it out for myself, but it's always good to have some help!

My idea is to check the chat box to see if it contains '/pm' within it upon hitting Return. But I have no idea how to check this through events. Any ideas?
B
25
S
10
G
1
Posts: 154
Reputation: 2,687

Post » Wed Oct 19, 2016 5:33 pm

I would do it like this:

Button: On clicked
-- TextBox_input: Text is NOT "" (case insensitive) <----- Check if the user has written something in the input textbox
-- tokenat(TextBox_input.Text, 0, " ") = "/pm" <-----Check if the first token index (0) in the TextBox_input.Text is "/pm"
-----> TextBox_output: Set text to mid(TextBox_in.Text, len(tokenat(TextBox_in.Text, 0, " ")), (len(TextBox_in.Text)-len(tokenat(TextBox_in.Text, 0, " "))))

The action "TextBox_output: Set text..." just sets the text in the output to all characters that come after the "/pm".
I hope this helps! :)
Image
B
5
S
3
Posts: 193
Reputation: 1,063

Post » Wed Oct 19, 2016 7:49 pm

Ahhh so complicated, I can't seem to make sense of it! I don't understand the whole token thing, what is a token? And then it gets even more crazy with the 3rd event! I'm sorry for taking up your time, but do you think you could explain more in-depth for me? I want to learn :)
B
25
S
10
G
1
Posts: 154
Reputation: 2,687

Post » Wed Oct 19, 2016 9:35 pm

The tokenat expression is actually quite simple. It works like this: tokenat(text, index, seperator)
The text ist just the input. The index is 0 based, so if you have a text like this "Hello World" and you use index 0 with whitespace as the seperator (you have to input " " for whitespace) you will get the word "Hello". Index 1 will return "World". This way I check the first 'word' in the input. If it is /pm the condition is true. The third event uses a number of system expressions to filter out the "/pm" and only return the text after it. Basically it uses the mid() expression to get the text from a specific starting point (index) to an end point. I set the starting point with a combination of len() and tokenat(). Len() returns the number of characters in a string so i put in the tokenat(textbox_in.text, 0, " ") to get the number of characters from the "/pm" command. This will be 3 everytime for "/pm" but this will make it more dynamic. After that I have to set the end point (index). This is just the length of the whole text ( len() expression again) minus the lenght of the "/pm" command (3 characters).
That should be everything for this example :D
I hope you can understand :)
Feel free to ask anything!
Image
B
5
S
3
Posts: 193
Reputation: 1,063


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 31 guests

cron