Author Topic: If !$= not working (solved)  (Read 1360 times)

Code: [Select]
%pos=%client.player.getPosition();
if(%client.player.oldPosition !$= mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2)))
{
    warn(%client.player.oldPosition);
    echo(mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2)));

I know for a fact they are the same too.

Also tried to do an else/if block, which means I must be doing something wrong here. This is how oldPosition is defined in a separate function.

Code: [Select]
%pos=%client.player.getPosition();
%client.player.oldPosition=mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2));
« Last Edit: July 21, 2014, 10:03:12 AM by Thorfin25 »

This might work better (notice the extra parenthesis around the string)

if(%client.player.oldPosition !$= (mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2))))

But that's also long and unreadable. Why not do it like this?

%pos = mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2));

if(%client.player.oldPosition !$= %pos)

Couldn't you just do

%p = mFloor(getWords(%pos, 0, 2));
if(%client.player.oldPosition !$= (%p))
//blah

Couldn't you just do

%p = mFloor(getWords(%pos, 0, 2));
if(%client.player.oldPosition !$= (%p))
//blah
You can't use mFloor on multiple words at a time. Doesn't work like that unfortunately :/

You can't use mFloor on multiple words at a time. Doesn't work like that unfortunately :/
Code: [Select]
function mFloorMulti(%words)
{
%count = getWordCount(%words);

for(%i = 0; %i < %count; %i++)
{
%words = setWord(%words, %i, mFloor(getWord(%words, %i)));
}

return %words;
}

Writing a for loop for three numbers seems a little out there.

If it's solved, say what the problem was?

The problem was the order in which the code is executed.

if( %client.player.oldPosition !$= mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2)) )

is compiled like

if( ( %client.player.oldPosition !$= mFloor(getWord(%pos,0)) ) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2)) )

but we want

if( %client.player.oldPosition !$= ( mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2)) ) )
« Last Edit: July 21, 2014, 01:28:33 PM by Zeblote »

The problem was the order in which the code is executed.

if( %client.player.oldPosition !$= ( mFloor(getWord(%pos,0)) SPC mFloor(getWord(%pos,1)) SPC mFloor(getWord(%pos,2)) ) )

Yeah this, silly little mistake. Better to set up the strings before throwing it in an if .-.

Yeah this, silly little mistake. Better to set up the strings before throwing it in an if .-.
It's not silly - I'm pretty sure every other language would have joined the strings first.

Well better to have an unrelenting richard of a language to make you safer if you go to another, rather than sorry XD