How do I send a /pm in Chat Box

0 favourites
  • 4 posts
From the Asset Store
Chat with smart animals using the OpenAi Chat GPT 3 API
  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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!

  • 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

  • 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

    I hope you can understand

    Feel free to ask anything!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)