Author Topic: Can't correctly manipulate quotation marks in a string  (Read 4113 times)

I'm currently trying to convert a string with quotation marks into a proper for to be able to send to the server through a command. It's using a GUI but I can't seem to properly replace quotation marks to be able to be sent.

So let's say I have a string that is stored like this
Code: [Select]
%str = "Hello \"Bob\"";and if you echoed %str it would display as
Hello "Bob"

I am trying to make it so if you type something into a GUI text box like this  Hello "Bob"  it'll properly put \'s into the string before them.

It's used for something like this
Code: [Select]
In the GUI lets say you type [i]you "suck" bob[/i] it would give me a syntax error because it thinks the quotation marks are for the command to server.
commandtoserver('tell', "Bob \"" @ GUIText.getValue() @ "\"");
I know something like this can be done another way with something with more parameters, but in the case of what I'm trying to achieve, I need to figure out how to do this.

I tried using strreplace(%str, "\"", "\\\""); but that didn't seem to give me proper results and still came back with syntax errors.

Hopefully that is understandable. If not, I will find another way to do this. Thanks for any help I receive.

You're actually in luck. The forward slash is only needed when you're defining a string, i.e. it's used between an opening and closing ". Since Torque doesn't evaluate strings as code, you only need to use the forward slash to get the strings in there, once they're in there they're stored without the slash.

Basically, you don't need to do anything. You can send the string with " in it without a problem.

You're actually in luck. The forward slash is only needed when you're defining a string, i.e. it's used between an opening and closing ". Since Torque doesn't evaluate strings as code, you only need to use the forward slash to get the strings in there, once they're in there they're stored without the slash.

Basically, you don't need to do anything. You can send the string with " in it without a problem.
Thank you for clarification, I found that I wasn't actually doing something correctly.

You're actually in luck. The forward slash is only needed when you're defining a string, i.e. it's used between an opening and closing ". Since Torque doesn't evaluate strings as code, you only need to use the forward slash to get the strings in there, once they're in there they're stored without the slash.

Basically, you don't need to do anything. You can send the string with " in it without a problem.

Psst, that's a backward slash.

One more question. Is there a max character limit to arguments in a function?

One more question. Is there a max character limit to arguments in a function?
No, but you can't send more than 256 characters in a server/client command.

No, but you can't send more than 256 characters in a server/client command.
wat. like seriously? i thought it was 16 or something.

wat. like seriously? i thought it was 16 or something.
If it was 16 then your chat messages would be much more limited in length than they currently are.

wat. like seriously? i thought it was 16 or something.

Cruxeis: What is this s-

Chat does not work this way, no. You may be thinking about the limit on arguments.
Not sure if there is a specific one for commands, but all TS functions (including serverCmd/clientCmd callbacks) have a limit of 20 arguments.

Cruxeis: What is this s-

Chat does not work this way, no. You may be thinking about the limit on arguments.
Not sure if there is a specific one for commands, but all TS functions (including serverCmd/clientCmd callbacks) have a limit of 20 arguments.
Oh wow. I'm blind - didn't see the "character limit" lol. Thought we were talking about the number of args. Gj me

Psst, that's a backward slash.
yeah, i noticed it after I posted and I hoped nobody else would notice. Guess that didn't work too well.

Sorry for all the questions and now it's not even on topic, but I really find it pointless to make a new topic. Anyways, I'm making something that I can announce stuff while on another server using TCPObjects, but they don't seem to be working.

Code: [Select]
new TCPobject(AServerTCP);

function AServerTCP::onConnectRequest(%this, %ip, %socket)
{
%this.connection[%ip] = new TCPobject("",%socket) {
class = AClientTCP;
parent = %this;
};
}

function AServerTCP::onLine(%this, %line)
{
announce(%line);
}
AServerTCP.listen(3000);

function AClientTCP::onLine(%this, %line)
{
echo(%line);
}

function AClientTCP::onConnected(%this)
{
$LRA::Connected = 1;
}

function AClientTCP::onDisconnect(%this)
{
      %this.delete();
}

$LRA::Connected = 0;
function LongRangeAnnounce(%ip, %port, %msg) {
if(!$LRA::Connected) {
$LRA::TCP = new TCPobject(AClientTCP);
$LRA::TCP.connect(%ip @ ":" @ %port);
}
$LRA::TCP.send(%msg);
}
Obviously it's not secured yet, but I'm trying to get the basics working first. It connects successfully, but when I send stuff from the client, onLine is not receiving anything.

The individual connection is handled by the no-name object you create in onConnectRequest, not the AServerTCP. Change it to something like this to receive the data:

function AServerTCP::onConnectRequest(%this, %ip, %socket)
{
   %this.connection[%ip] = new TCPobject(AServerTCP_Inst, %socket)
   {
      parent = %this;
   };
}


And then you can do this:

function AServerTCP_Inst::onLine(%this, %line)
{
   announce(%line);
}

Still doesn't seem to work.

Did you do TCPObject.listen(portHere); ?