Author Topic: What's wrong with my script?  (Read 3401 times)

I'm trying to make a script  that clears music bricks. This isn't actually my first script, It's my first script that I cared enough about to try and fix.

This is what I have in my Script_ClearMusicBricks folder

server.cs
    
Code: [Select]
exec("./camb.cs");
camb.cs
    
Code: [Select]
function servercmdClearMusicBricks
{
if(!%client.isAdmin)    
        return;

camb();
}

function camb()
{
   if($Server::BrickCount > 0)
messageAll('MsgClearBricks', "\c3" @ %client.getPlayerName() @ "\c0 cleared music bricks.");

   %groupCount = MainBrickGroup.getCount();
   for(%i = 0; %i < %groupCount; %i++)
   {
      %group = MainBrickGroup.getObject(%i);
      %count = %group.getCount();
      for(%j = 0; %j < %count; %j++)
      {
         %brick = %group.getObject(%j);

if(!%brick.getType() & $TypeMasks::fxDtsBrickData(brickmusicdata)
             continue;
         if(!%brick.isPlanted)
             continue;

if(%brick.isDead)
continue;
}



description.txt
    
Quote
Title: Clear Music Bricks
     Author: Jelly
     No more annoying unauthorized music.

namecheck.txt
    
Quote
Script_ClearMusicBricks

I was wondering if you guys could tell me why it's not showing up in my Add-Ons folder? I just started scripting a week ago.
« Last Edit: September 16, 2012, 11:45:58 PM by Miner Blockman »

Tech support debugging #1: is it actually in your add-ons folder?

----
Preference: move camb.cs contents to server.cs
Namecheck.cs is not necessary for add-on execution.

Tech support debugging #1

Wh... Wha?

I have so much to learn.


Namecheck.cs is not necessary for add-on execution.

I didn't know, I've been studying Scripts to learn what I know now.
« Last Edit: September 16, 2012, 09:44:12 PM by Miner Blockman »

Preference: move camb.cs contents to server.cs
Namecheck.cs is not necessary for add-on execution.
More info on this:
1. Unless you have certain conditions (such as required add-ons) that need to be met to exec, which you don't, having server.cs exec another file with contains your code is entirely pointless. Move your code into server.cs and delete camb.cs
2. Namecheck is not required, it's used to prevent execution if the add-on .zip was renamed, don't worry about it at all unless you plan or releasing it (and even then, RTB adds it automatically)
As for what's preventing it from showing in the add-on list, I don't see any issues. Maybe you put it in the wrong folder?

When you do get it to show up, you'll definitely have syntax and logic errors

You're missing Parentheses after
Code: [Select]
servercmdClearMusicBricks

You're missing Parentheses after
Code: [Select]
servercmdClearMusicBricks
There's a ton of other errors (that I'm typing up corrections for), but right now the issue is getting it to show up in the add-ons list


Edit: Try thing, after you get it to show in the list:
Code: [Select]
function servercmdClearMusicBricks(%client)
{
if(!%client.isAdmin)     
        return;

camb();
}

function camb()
{
if($Server::BrickCount > 0)
{
messageAll('MsgClearBricks', "\c3" @ %client.getPlayerName() @ "\c0 cleared music bricks.");

  %groupCount = MainBrickGroup.getCount();
  for(%i = 0; %i < %groupCount; %i++)
    {
%group = MainBrickGroup.getObject(%i);
%count = %group.getCount();
for(%j = 0; %j < %count; %j++)
{
%brick = %group.getObject(%j);

if(%brick.getDatablock().getName() !$= "brickMusicData")
continue;
if(!%brick.isPlanted)
continue;
if(%brick.isDead)
continue;

%brick.delete();
}
}
}
}

Issues fixed:
Missing arguments in the serverCmdClearMusicBricks function declaration
If and messageAll placement would result in announcing the clear bricks only if there are bricks on the server, but attempting to clear music bricks even if there are no bricks
Incorrect way of checking if the brick is a music brick
Not doing anything to the brick if it passed exclusion conditions
Missing brackets
« Last Edit: September 16, 2012, 09:56:50 PM by Headcrab Zombie »

Thanks, Headcrab.

A while ago, I wanted to script, so I was being stupid and changed the default program to open .zip files to Notepad. I can't change it back.

About two weeks ago, I downloaded a program called The Extractor: Unzips files. I unzipped scripts and used them as references to start scripting. I'm unzipping the Script_ClearMusicBricks with it, and it claims that nothing is in the folder.

I'm so loving confused.


Nevermind, there was an open folder in the Script_ClearMusicBricks file called Script_ClearMusicBricks. This might be what's causing the problem
« Last Edit: September 16, 2012, 10:19:58 PM by Miner Blockman »

A while ago, I wanted to script, so I was being stupid and changed the default program to open .zip files to Notepad. I can't change it back.
Right click a zip file, and click properties. Near the top, it should say "Opens with" click the change button next to it.

I've never heard of The Extractor; get something like winrar instead

Right click a zip file, and click properties. Near the top, it should say "Opens with" click the change button next to it.

I can't open it with a blank file.
« Last Edit: September 16, 2012, 11:46:36 PM by Miner Blockman »

More info on this:
1. Unless you have certain conditions (such as required add-ons) that need to be met to exec, which you don't, having server.cs exec another file with contains your code is entirely pointless. Move your code into server.cs and delete camb.cs
It's pointless either way. You can just put a return if the file is not found.

It's pointless either way. You can just put a return if the file is not found.
Yes, there are other ways that I prefer more, but in that example case, doing it that way isn't entirely pointless

@OP Another time you'd have server.cs exec other files is if it's a very large add-on and you want organization, so you'd divide your code into multiple files.

There's a ton of other errors (that I'm typing up corrections for), but right now the issue is getting it to show up in the add-ons list


Edit: Try thing, after you get it to show in the list:
Code: [Select]
function servercmdClearMusicBricks(%client)
{
if(!%client.isAdmin)     
        return;

camb();
}

function camb()
{
if($Server::BrickCount > 0)
{
messageAll('MsgClearBricks', "\c3" @ %client.getPlayerName() @ "\c0 cleared music bricks.");

  %groupCount = MainBrickGroup.getCount();
  for(%i = 0; %i < %groupCount; %i++)
    {
%group = MainBrickGroup.getObject(%i);
%count = %group.getCount();
for(%j = 0; %j < %count; %j++)
{
%brick = %group.getObject(%j);

if(%brick.getDatablock().getName() !$= "brickMusicData")
continue;
if(!%brick.isPlanted)
continue;
if(%brick.isDead)
continue;

%brick.delete();
}
}
}
}

Issues fixed:
Missing arguments in the serverCmdClearMusicBricks function declaration
If and messageAll placement would result in announcing the clear bricks only if there are bricks on the server, but attempting to clear music bricks even if there are no bricks
Incorrect way of checking if the brick is a music brick
Not doing anything to the brick if it passed exclusion conditions
Missing brackets


I always advise people to use variables instead of functions, IE:

%client.name
%client.player.position
%client.player.rotation

Etc.

I always advise people to use variables instead of functions, IE:
%client.name
%client.player.position
%client.player.rotation
Etc.
Badspot himself advises to use getPlayerName() instead of name:
Quote from: v10 to 11 change log
Client name is now accessed through %client.getPlayerName() (%client.name is still provided for backward compatibility but %client.getPlayerName() is preferred)
and I'm sure others of more experience would also advise the same for getPosition and getRotation

There's no real difference between the member field and the function, but someone easily could just go %player.position = "ur moms panties lol";

Badspot himself advises to use getPlayerName() instead of name:and I'm sure others of more experience would also advise the same for getPosition and getRotation

Preferences are personal, and are you implying that i am not experienced?