Author Topic: Syntax error  (Read 8271 times)

It will ignore spaces that are before coding, and some while in the code, so if you took
Code: [Select]
function nig(%a)
{
    if(%a==8675309)
    {
        //dostuff
    }
}
It will be the same as
Code: [Select]
function nig(%a)
{
if(%a==8675309
{
//dostuff
}
}
Or spaces in things like "The number is: " @ %a @ "." can be ignored and work the same as "The number is "@%a@"." But in cases of things like that, no. It will always register spaces, but some parts of code spaces can be ignored.

I thought torque didnt register spaces?

Torque ignores spacing. It does not ignore spaces. There's places in code where the interpreter has finished its current step and is yet to begin its next step, here you can place as many spaces as you like. For example:

Code: [Select]
%string=   "spacing works"     ;
      echo   (        %string) ;

That would work just fine. However, this wouldn't:

Code: [Select]
%string = "this doesn't";
ech o(%string) ;

Neither would this:
Code: [Select]
%string = "this doesn't";
echo(%st ring) ;

So basically, in the middle of what's called a token (this would be a word like "echo" or "%string") spaces will break everything. However, in between tokens (like right before the line-end token [a semicolon] or right after the name of something) spaces work just fine.

$Pref::Player:NetName is a single token because the whole thing refers to one variable. However, once that token is over (right after the last e) you can put as many spaces as you like.

Okay I got an error yet again

package chatbot
{
function clientcmdchatmessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg)
 {
parent::clientCmdChatMessage(%a, %b, %c, %fmsg, %cp, %name, %cs, %msg);
   if (%msg $= "Zazzlebot")
   {
      if (%name $=$Pref::Player::Netname)
      {   
      commandtoserver('messagesent',"Yissir");
      }
   }
}
};
activatepackage(chatbot);

Ive decided that Ive run into too many errors with this and Im going to move back to something else to help with my scripting. If anyone could lead me to a good tutorial without problems, that'd be amazing. I'll also like if someone could tell me of another script I could try that would be more useful for practice. Thank you all for the support. Ill make sure to keep what you've all said in mind



It works fine for me

Two things:
Please work on your formatting. Everything between brackets gets indented one tab (not just one space). If you put more brackets inside (nested) those brackets, the contents of those brackets go in another tab. If you get a text editor made especially for coding, like TorqueDev or even just Notepad++, it'll be a lot of it for you, or at least make it easier. Please improve your formatting before making more help threads, as it not only makes it easier for us to read your code and tell what's wrong, but by formatting properly from the start, you can completely eliminate many extra/missing brackets or parenthesis right from the start

Never simply say "it doesn't work" "I got an error"
Tell us what the error is. If it's a syntax error, the error report says where the error is, screenshot (or at least copy/paste) it so we don't have to read through the entire code. Since it tells you where the error is, you can also make at attempt to fix it yourself. If it's a logic error (which is when it executed fine but doesn't work properly)  tell us exactly what doesn't work properly
« Last Edit: August 05, 2014, 06:31:29 PM by Headcrab Zombie »



It works fine for me

What? Thats strange. My console keeps saying I have a syntax error

What? Thats strange. My console keeps saying I have a syntax error
Are you coding from inside a zip file?
If so, don't. Don't put your files in a zip file until it's going to be released (which a chatbot such as this should never be)
If not, try restarting the game
Also, I editted my above post, if you can read it

No Im not coding in a zip file.

« Last Edit: August 05, 2014, 06:44:13 PM by Ipquarx »

Erm... Try opening the file in notepad. Not wordpad or word, notepad.

On Macs the notepad application is named "TextEdit."

On Macs the notepad application is named "TextEdit."
Well stuff, that completely flew right over my head. I'm outta here, I have no idea how macs work lol.

Annnnd thats the end of my crappy scripting career until I get a pc xD I guess its textedit then

The text editor you're using is appending a bunch of formatting things to the file
You just need to get a different text editor, something that edits plain text. There's plenty of mac choices.

I saved the text file as client.cs and theres a description.txt next to it so I dunno whats wrong at all. It worked for someone else for some reason

The text editor you're using is appending a bunch of formatting things to the file
You just need to get a different text editor, something that edits plain text. There's plenty of mac choices.

Alright, do you think xcode would work for this?

Alright, do you think xcode would work for this?
I'd advise against using XCode, since it isn't made for TorqueScript.