Author Topic: String replacing and modifying the wrench.....  (Read 4817 times)

Okay, so I have a string...I want to find a certain text in it, and change it. Ex...
%string = "Bla, bla2, bla3, bla4";
And I wanna make Bla3 something else. How can I do this? (This is probably a stupid question...)
« Last Edit: March 13, 2007, 06:23:36 PM by Aloshi »

rudyman

  • Guest
Okay, so I have a string...I want to find a certain text in it, and change it. Ex...
%string = "Bla, bla2, bla3, bla4";
And I wanna make Bla3 something else. How can I do this? (This is probably a stupid question...)

%string=strReplace(%string,"bla3","something else");

Syntax: strReplace( [string] , [what you want to replace] , [what to replace it with] );

It's case sensitive.

HMK

Torque code isn't case sensitive.

Torque code isn't case sensitive.
The strings are case sensitive, you brain dead.


Okay, so I have a string...I want to find a certain text in it, and change it. Ex...
%string = "Bla, bla2, bla3, bla4";
And I wanna make Bla3 something else. How can I do this? (This is probably a stupid question...)

%string=strReplace(%string,"bla3","something else");

Syntax: strReplace( [string] , [what you want to replace] , [what to replace it with] );

It's case sensitive.
You can also use Getword to find the third word then replace it.

Code: [Select]
%string = "Bla, bla2, bla3, bla4";
%word = getWord("bla1 bla2 bla3 ",2);
%result = strReplace(%string,%word,"[Replace Me plz]");

Sorry for Double-Post !

k, works. Thanks a bunch. :D

One more question, I won't make another thread as it doesn't deserve it: How can I add an onCollision to the wrench? I tried
Code: [Select]
function WrenchProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
//Code here pls.
Parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
}
My code works, but the wrench doesn't do anything on normal bricks.
« Last Edit: March 13, 2007, 07:20:49 PM by Aloshi »

Okay, so I have a string...I want to find a certain text in it, and change it. Ex...
%string = "Bla, bla2, bla3, bla4";
And I wanna make Bla3 something else. How can I do this? (This is probably a stupid question...)

%string=strReplace(%string,"bla3","something else");

Syntax: strReplace( [string] , [what you want to replace] , [what to replace it with] );

It's case sensitive.
You can also use Getword to find the third word then replace it.

Code: [Select]
%string = "Bla, bla2, bla3, bla4";
%word = getWord("bla1 bla2 bla3 ",2);
%result = strReplace(%string,%word,"[Replace Me plz]");

Sorry for Double-Post !
You messed up
Code: [Select]
%string = "Bla, Bla2, Bla3, Bla4";
%word = getWord(%string,2);
%result = strReplace(%string,%word,"This Is The Replacement Text");

k, works. Thanks a bunch. :D

One more question, I won't make another thread as it doesn't deserve it: How can I add an onCollision to the wrench? I tried
Code: [Select]
function WrenchProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
//Code here pls.
Parent::onCollision(%this,%obj,%col,%fade,%pos,%normal);
}
My code works, but the wrench doesn't do anything on normal bricks.
Trying to use my method of teleport-setting? Good luck getting the Wrench to work. You'll be able to see how I did it when I release mine soon.

Trying to use my method of teleport-setting?

No, I'm not even working on teleporters. Yours will probably be the best for a loooong time. I'm making an admin-dewrencher code, and I just want to add something so that players can't use wrenches if a certain thingy is set. It all works except for the wrench part - you can't wrench when it's set etc. but if it should be working as if it isn't taken away, nothing happens in the oncollision. I'd settle for the onuse also. >_>
« Last Edit: March 14, 2007, 04:25:43 PM by Aloshi »

I can't guarantee that there isn't more to the code than this, but this is how I imagine the wrench collision to be:

function WrenchProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
     %client = %obj.client;
     %client.wrenchbrick = %col;
     messageClient(%client,<msgcallback that opens the client's wrench gui>,'');
}

Also, if you were wanting to limit wrench use, you could change it to something like this:

function WrenchProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
     %client = %obj.client;

     if(!%client.nowrench) // <- A property you'd have to assign to the client for wrench permissions.
     {
          %client.wrenchbrick = %col;
          messageClient(%client,<some msgcallback that opens the client's wrench gui>,'');
     }
}

That should be all there is to it.

Rudy, how do you search a string for a word then replace it, like a swear word?

rudyman

  • Guest
Rudy, how do you search a string for a word then replace it, like a swear word?

Use a for() loop to go through each swear word, and another to go through each word in a string and check for matches.

EX:

Code: [Select]
for(%i=1;%i<=$swearWordCount;%i++)
{
%currSwear=$swearWord[%i];
   for(%w=0;%w<getWordCount(%string);%w++)
   {
   %currWord=getWord(%string,%w);
      if(%currWord $= %currSwear){...} //Found a swear word
   }
}

It's actually better to use strStr() instead of the second loop, because otherwise they could mask swear-words by putting them inside other words.
(For example, if you made аss a swear, the method above wouldn't detect аssholе).
« Last Edit: March 15, 2007, 07:56:39 AM by rudyman »

Rudy, how do you search a string for a word then replace it, like a swear word?

Use a for() loop to go through each swear word, and another to go through each word in a string and check for matches.

EX:

Code: [Select]
for(%i=1;%i<=$swearWordCount;%i++)
{
%currSwear=$swearWord[%i];
   for(%w=0;%w<getWordCount(%string);%w++)
   {
   %currWord=getWord(%string,%w);
      if(%currWord $= %currSwear){...} //Found a swear word
   }
}

It's actually better to use strStr() instead of the second loop, because otherwise they could mask swear-words by putting them inside other words.
(For example, if you made аss a swear, the method above wouldn't detect аssholе).
O.o
Code: [Select]
for(%i=1; %i <= $swearWordCount; %i++){
   strreplace(%string, $swearWord[%i], "*beep*");
}

rudyman

  • Guest
O.o
Code: [Select]
for(%i=1; %i <= $swearWordCount; %i++){
   strreplace(%string, $swearWord[%i], "*beep*");
}


how do you search a string for a word then replace it