Author Topic: setWord  (Read 2191 times)

setWord won't seem to work for me.  Has it been removed or broken?

In the console to test this out I did:

$a = "1 1 1";
setWord($a, 1, "3");
echo($a);

When it echos, $a still reads as 1 1 1 when it should've been 1 3 1.
« Last Edit: August 18, 2013, 08:48:11 PM by Vaux »

I've never heard of that function. Does it even exist? Try $a = setword($a, 1, "3");

It doesn't give me a syntax error whenever I input it, which tells me that its a function.  And I also used this reference: https://bldocs.readthedocs.org/en/latest/string.html

I've never heard of that function. Does it even exist? Try $a = setword($a, 1, "3");
Awesome, thanks.  That worked.


setWord and other functions don't automatically modify the variable you give them. You have to use %variable = function(%variable, %args)

Also, isn't setWord 0 indexed (first word is 0)?

setWord and other functions don't automatically modify the variable you give them. You have to use %variable = function(%variable, %args)

Also, isn't setWord 0 indexed (first word is 0)?
It's indexed

hmmmmm
LOL, just noticed that

'string setword(var text, var index, var replace); - Used to replace the word at index with replace within text.'
 - TorqueDev

Booldals is correct. No Torque function can modify the variable pushed to it unless it is global. Even then, it creates a local copy of it.

%a = "1 1 1";
%a = setWord(%a, 1, "3");
echo(%a);

Similarly, doing this:
Code: [Select]
function addOne(%num) { %num = %num + 1; }

%x = 1;
addOne(%x);
echo(%x);
will echo 1.
« Last Edit: August 19, 2013, 01:22:26 AM by $trinick »

Right, it returns a value. You assign that returned value to some sort of variable of your choice. It is the same for quite a bit of languages.

Booldals is correct. No Torque function can modify the variable pushed to it unless it is global. Even then, it creates a local copy of it.

Doesn't nextToken set a local variable in the callee's scope? I don't remember though because I never use it for anything.

Doesn't nextToken set a local variable in the callee's scope? I don't remember though because I never use it for anything.
Okay, you're right. I made a sweeping generalization. But token handling functions are the only functions I know of that do this, so it's an extreme exception.