Author Topic: Help debugging a simple script  (Read 857 times)

I am trying to get this simple script, which when someone tries to toggle their player light, it checks whether they're admin, enabling the light when they are, otherwise returning a chat message.

The game claims the error is at the last line of the script, but I see nothing.
Is it because I falsely attempted to pack the meat of the script in a single line?
Here's the whole thing:

Code: [Select]
package NoPlayerLight
{
function servercmdLight(%client)
{
if(%client.isAdmin) Parent::servercmdLight(%client); else messageClient(%client,'',"Player lights are disabled for non-admins.");
}
};
activatePackage(NoPlayerLight);

I can't see much in the way of something wrong with it other than you making the code super ugly. You should never compact code like that. Not only do you not improve performance (not that it matters (on such a small scale)), you demolish the readability of the code.
« Last Edit: February 06, 2016, 01:36:48 PM by Dannu »

Okay well first off, never ever put all your code on one line like that. Format it like this:
Code: [Select]
package NoPlayerLight
{
function servercmdLight(%client)
{
if(%client.isAdmin)
Parent::servercmdLight(%client);
else
messageClient(%client,'',"Player lights are disabled for non-admins.");
}
};
activatePackage(NoPlayerLight);

And I don't see anything wrong with it. If you're putting this in a zip file, make sure you do discoverFile("add-ons/addon_name.zip"); before re-executing the addon.

torque gets angry if you put an if statement without curly brackets on one line like that
so don't do it

torque gets angry if you put an if statement without curly brackets on one line like that
so don't do it

No it doesn't

No it doesn't
i swear it never worked with me
but you're right i just tested it
i am bamboozled

Isn't it toggleLight(%client);?

Isn't it toggleLight(%client);?
no such function exists by default

torque gets angry if you put an if statement without curly brackets on one line like that
so don't do it
Torque only gets angry if you execute more than one function or script on the same line like
Code: [Select]
if(1)
      echo("hi!"); return;
In that case you have to use brackets.

Torque only gets angry if you execute more than one function or script on the same line like
Code: [Select]
if(1)
      echo("hi!"); return;
In that case you have to use brackets.

That code works fine aswell. There's a difference between "it doesn't run" and "it doesn't run as expected"