blank spaces at the end of a string switch.

Currently working on a chat system for my project and want to be able to switch chat channels. Default channel is “say” and by writing /yell and pressing enter (commit) the channel would then switch to “yell”. This works.

But after testing it out, I was reminded on how World of Warcraft has multiple ways of doing it. In wow you could write /yell and press space, creating a blank space, and it would automatically make the switch. I tried replicating this by using a switch on string, hoping I could simply add /yell(blankspace) as a pin. Sadly the switch ignores the blank space and removes it.

Now I do have another solution, but it involves using a lot of if statements and starts with nodes, which could be alright if I only wanted 2 channels, but will quickly become a mess if I want 10 channels.

Do anyone have any ideas on how to solve this?

Thank you

You could templatize it so it can work with an infinite number of channels.

Whenever your chat text box changes, check if the first character is a ‘/’, the last character is ’ ’ and the text in-between is the same as a channel.

You say templatize. Is that just a word you are using to describe idea below or is that a node?

And with first character and last character are you thinking of “starts with” and “ends with”?

Templatize just means to make something into a template- which is an actual thing, but not in blueprints. It’s not the best word for the situation, but the best escapes me.

Yes, you can use the starts/ends with nodes to do what I’m talking about.
You’ll need to then use the substring node to get what’s in-between.

I see. I think I see where you are going.

Using the Get Substring with an start index of 1 and length of original string length -1, I would be able to isolate yell from /yell(blankspace). I then do a string switch using the Get Substring output? Does that sound solid?

That is exactly what I meant, yea.
Though it’s probably best if you don’t use a switch statement.
Depending on how you’ve implemented the channel system, that may be really easy. But there are so many different ways you could’ve implemented it that I can’t really suggest anything concrete.

I just cant really think of another way, right here on the spot.

Unless a map is something that could be done. I dont have much experience in that tho

You can likely do it with a single map.

Maps simply map one thing to another. These two things can be the any variable type.
Meaning you can map a string to an int, an int to an object, or an object to and object. Any type to any type. All of the keys of a map are unique. You can have multiple identical values, but you can’t have identical keys.

How’ve you implemented channels?

I suppose I worded my original post poorly. Everything that I have done so far is UI stuff. I haven’t actually done anything server side as of yet.

Okay- how’ve you implemented the visuals for channels? What does your switch statement do exactly? Screenshots would be much appreciated.



This is what I quickly did. Doesn’t actually work yet. Might be something to do with Starts With/Ends With/GetSubstring. Went away for a bit and have not taken a look at it.

Yeah the LEN Node should be subtracted by 2 instead of 1. Works now

Holy jesus christ.

So the first thing I’d recommend is putting all the change logic inside a function. It’s highly unlikely that you’ll only want to change the channel type by just input.

Here’s how I would do it:


We just use a select statement off our current type.

For the actual switching, I would make a String->EChannelType map.
image
You can then make it blueprint read only since you don’t want this to be changed:
image
And fill out the defaults to be your commands mapped to which channel they should switch to:
image



To actually implement this map, you can just use the find node. If it found something, that means it’s a valid channel. We then clear the text box and set to the correct channel.

Great stuff. Was thinking about select, but didn’t know to make it happen.
You’ve been of great help.
Thanks alot

1 Like

Just wanted to let others know incase they need the same solution. The clear text function should either be placed inside of SetChannelType or after SetChannelType has been called. Not doing this will result the string we’re using to be empty.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.