Author Topic: If statement not working?  (Read 1235 times)

Yes
And it will only return one word of the text

Will it return a number if it is seperated by spaces?

Like so,
JazZ: hey 1 there
getWord(%msg, 2)
Will that return 1?

Yes because the numb is a word in that case

No it won't return 1, it will return there.

Because the index starts at 0, not 1.

Does noone notice the lack of sense?
If %msg is "Hi There", getWord(%msg, 4) will always return "".
The script is probably WIP.

Also with the echo it did echo
Code: [Select]
JazZ JazZ Hi there Exactly that was in console
Then I'm not sure why it's making you talk when anybody in the server says something.

I don't do much work with client mods, but clientCmdChatMessage may be the function which the server makes you call in order to display the message on your screen. Is there maybe a clientCmdChatMessageSent function?
If this is the display function, it may be displaying both because it displays your initial message, returns true, saying "Hi there" calls it again, and that time it returns false.
But that might be wrong because otherwise i think you would be saying "dumb" infinitely[/s]

Warning - while you were typing 4 new replies have been posted. You may wish to review your post.

Will it return a number if it is seperated by spaces?

Like so,
JazZ: hey 1 there
getWord(%msg, 2)
Will that return 1?
No, that will return the third word in message.
Meaning if %msg was "Hello my name is blockhead", it would return "name"

Warning - while you were typing 2 new replies have been posted. You may wish to review your post.
goddamn i must type slow

No it won't return 1, it will return there.

Because the index starts at 0, not 1.
Whoops

The script is probably WIP.
Then I'm not sure why it's making you talk when anybody in the server says something.

I don't do much work with client mods, but clientCmdChatMessage may be the function which the server makes you call in order to display the message on your screen. Is there maybe a clientCmdChatMessageSent function?
If this is the display function, it may be displaying both because it displays your initial message, returns true, saying "Hi there" calls it again, and that time it returns false.
But that might be wrong because otherwise i think you would be saying "dumb" infinitely


Warning - while you were typing 4 new replies have been posted. You may wish to review your post.
No, that will return the third word in message.
Meaning if %msg was "Hello my name is blockhead", it would return "name"

Warning - while you were typing 2 new replies have been posted. You may wish to review your post.
goddamn i must type slow

I'm more than sure I'm using the correct function, I've used multiple times before with no errors like this, I'm going to try to dumb down the script and find out what my issue is here, then solve it.

Thanks for the help guys


Do not lock this
I'll post results when done, not locking it

Okay guys I've found the only remaining problem, as well as sorted out the rest.

I got it to work, but my issue is when I actually send the chat message it seems to be calling the function twice.
Like:
JazZ: Hi
JazZ: Said Hi
JazZ: Said Hi

You see?

Code: [Select]
package SimpleTest
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%name $= $Pref::Player::NetName)
{
schedule(50, 0, SendMessage);
}
}
};
activatepackage(SimpleTest);

function testWord(%msg)
{
getWord(%msg, 0);
return;
}

function SendMessage()
{
%TestVar1 = testWord(%msg);
commandToServer('messagesent',"Jazzy: " @ %TestVar1);
return;
}

This has this problem, anyone have a reason as to why?

because you have testWord to return nothing, so %TestVar1 will always be blank.

Okay guys I've found the only remaining problem, as well as sorted out the rest.

I got it to work, but my issue is when I actually send the chat message it seems to be calling the function twice.
Like:
JazZ: Hi
JazZ: Said Hi
JazZ: Said Hi

You see?

Code: [Select]
package SimpleTest
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
{
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
if(%name $= $Pref::Player::NetName)
{
schedule(50, 0, SendMessage);
}
}
};
activatepackage(SimpleTest);

function testWord(%msg)
{
getWord(%msg, 0);
return;
}

function SendMessage()
{
%TestVar1 = testWord(%msg);
commandToServer('messagesent',"Jazzy: " @ %TestVar1);
return;
}

This has this problem, anyone have a reason as to why?
That won't work anyways. local variables aren't pushed to other functions.


That won't work anyways. local variables aren't pushed to other functions.
Use a global variable then, I'll try that.

because you have testWord to return nothing, so %TestVar1 will always be blank.
How would I fix that?

Use a global variable then, I'll try that.
No, just pass the variables between functions correctly.
Never use global variables unless you have to

For instance, do this for the testWord function:
Code: [Select]
function testWord(%msg)
{
return getWord(%msg, 0);
}

you mean the 3rd

No, I do not
« Last Edit: August 31, 2012, 09:33:47 PM by Headcrab Zombie »

Still doesn't return correctly.

If anyone wants to help out with actually testing this, feel free.
I'm quite tired, done with scripting tonight, will pickup tomorrow