Author Topic: Good starting practice?  (Read 634 times)

I've recently started torque, and know the basics (functions, variables, loops, etc.) and couldn't find anything to practice on doing, although I'm not yet to the point where I can actually make anything.

Also, some code that I couldn't figure out why it wasn't working:
Code: [Select]
function speakToConsole(%words) {
    echo("You said: " @ %words);
    %words = strlwr(%words);
    if(%words == "hello") {
        echo("Hello to you too.");
    } else if(%words == "bye") {
        echo("Goodbye.");
    } else {
        echo("Sorry, I don't understand.");
    }
}
It keeps returning "Hello to you too." no matter what I put as %words.

== is for comparing numbers. In Torque, if you attempt to interpret strings as numbers, it will perceive them as 0. When you tried to compare strings with == it will do if(0 == 0). To compare strings or most any value you use $=.

You also don't need to make the entire message lower case for the comparison because it isn't case sensitive.

And instead of echo("You said: " @ %words); you can just do echo("You said:" SPC %words);
SPC connects the variable to the message with a space in between them. There's also NL which connects it with a new line and TAB which connects it with a tab.

could give you weapon models to work on if wanting to practice.

== is for comparing numbers. In Torque, if you attempt to interpret strings as numbers, it will perceive them as 0. When you tried to compare strings with == it will do if(0 == 0). To compare strings or most any value you use $=.
Ah, thanks. I was put under the impression that it was for strings and numbers. Code works now.
You also don't need to make the entire message lower case for the comparison because it isn't case sensitive.

And instead of echo("You said: " @ %words); you can just do echo("You said:" SPC %words);
SPC connects the variable to the message with a space in between them. There's also NL which connects it with a new line and TAB which connects it with a tab.
Again, thanks. Didn't realize "not case-sensitive" expanded to strings. And the SPC looks a little neater.
could give you weapon models to work on if wanting to practice.
Eh, I don't really feel comfortable with that quite yet, still haven't gotten into methods and parenting.

You also don't need to make the entire message lower case for the comparison because it isn't case sensitive.
string comparison isn't case-sensitive...?

string comparison isn't case-sensitive...?
Nope.

echo("oink" $= "Oink");
Will return true.

It's still possible to check case with strCmp though.