Raised This Month: $51 Target: $400
 12% 

Can't get the example code to compile


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
optimist prime
New Member
Join Date: Oct 2009
Old 10-01-2009 , 05:52   Can't get the example code to compile
Reply With Quote #1

Alright, after posting this is the completely wrong forum I'm mildly convinced the problem is that I'm just retarded but anyways...

Ok, so I'm trying to learn SourcePawn and I figured a good place would be the tutorials on the wiki.
this page specifically
So I read through it, partially understanding what was going on. Not entirely sure what everything was doing I decided to just copy paste the example, compile it and then see what I could do with the thing.
So I loaded my command prompt, went to the appropriate directory and typed "spcomp myplugin.sp" (which is what I had named it) and it told me "myplugin.sp(1) : error 010 invalid function or declaration" which is not the most helpful of error messages. What exactly does this error mean? What went wrong with the code?
Any help would be greatly appreciated.
Oh and the exact code I grabbed was
Code:

#include <sourcemod>
#include <sdktools> 
new Handle:sm_myslap_damage = INVALID_HANDLE
 
public Plugin:myinfo =
{
    name = "My First Plugin",
    author = "Me",
    description = "My first plugin ever",
    version = "1.0.0.0",
    url = "http://www.sourcemod.net/"
}
 
public OnPluginStart()
{
    LoadTranslations("common.phrases")
    RegAdminCmd("sm_myslap", Command_MySlap, ADMFLAG_SLAY)
 
    sm_myslap_damage = CreateConVar("sm_myslap_damage", "5", "Default slap damage")
    AutoExecConfig(true, "plugin_myslap")
}
 
public Action:Command_MySlap(client, args)
{
    new String:arg1[32], String:arg2[32]
    new damage = GetConVarInt(sm_myslap_damage)
 
    /* Get the first argument */
    GetCmdArg(1, arg1, sizeof(arg1))
 
    /* If there are 2 or more arguments, and the second argument fetch 
     * is successful, convert it to an integer.
     */
    if (args >= 2 && GetCmdArg(2, arg2, sizeof(arg2)))
    {
        damage = StringToInt(arg2)
    }
 
    /**
     * target_name - stores the noun identifying the target(s)
     * target_list - array to store clients
     * target_count - variable to store number of clients
     * tn_is_ml - stores whether the noun must be translated
     */
    new String:target_name[MAX_TARGET_LENGTH]
    new target_list[MAXPLAYERS], target_count
    new bool:tn_is_ml
 
    if ((target_count = ProcessTargetString(
            arg1,
            client,
            target_list,
            MAXPLAYERS,
            COMMAND_FILTER_ALIVE, /* Only allow alive players */
            target_name,
            sizeof(target_name),
            tn_is_ml)) <= 0)
    {
        /* This function replies to the admin with a failure message */
        ReplyToTargetError(client, target_count);
        return Plugin_Handled;
    }
 
    for (new i = 0; i < target_count; i++)
    {
        SlapPlayer(target_list[i], damage)
        LogAction(client, target_list[i], "\"%L\" slapped \"%L\" (damage %d)", client, target_list[i], damage)
    }
 
    if (tn_is_ml)
    {
        ShowActivity2(client, "[SM] ", "Slapped %t for %d damage!", target_name, damage)
    }
    else
    {
        ShowActivity2(client, "[SM] ", "Slapped %s for %d damage!", target_name, damage)
    }
 
    return Plugin_Handled;
}
optimist prime is offline
Kigen
BANNED
Join Date: Feb 2008
Old 10-01-2009 , 06:09   Re: Can't get the example code to compile
Reply With Quote #2

If you use certain text editors they will add a character to the very beginning of the file that SourceMod's compiler hates. Make sure your text editor is saving in ANSI encoding.
Kigen is offline
optimist prime
New Member
Join Date: Oct 2009
Old 10-01-2009 , 06:20   Re: Can't get the example code to compile
Reply With Quote #3

Ah. Wrong character encoding! Thank you very much sir it's compiling nicely now.
optimist prime is offline
psychonic

BAFFLED
Join Date: May 2008
Old 10-01-2009 , 07:35   Re: Can't get the example code to compile
Reply With Quote #4

Quote:
Originally Posted by Kigen View Post
Make sure your text editor is saving in ANSI encoding.
Or UTF-8 without BOM is also fine.
psychonic is offline
EHG
Senior Member
Join Date: May 2009
Location: 127.0.0.1
Old 10-01-2009 , 10:46   Re: Can't get the example code to compile
Reply With Quote #5

I recommend you try notepad++
It is only the best program ever for writing code ^_^
EHG is offline
crazydog
AlliedModders Donor
Join Date: Jan 2006
Old 10-01-2009 , 13:31   Re: Can't get the example code to compile
Reply With Quote #6

or Pawn Studio. I haven't had any major issues with it (although it's a little buggy.)

It's built for the Pawn language and AMXX/Sourcemod/etc, so it works with it nicely.
crazydog is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 10-01-2009 , 21:23   Re: Can't get the example code to compile
Reply With Quote #7

Quote:
Originally Posted by crazydog View Post
or Pawn Studio. I haven't had any major issues with it (although it's a little buggy.)

It's built for the Pawn language and AMXX/Sourcemod/etc, so it works with it nicely.
That tends to crash *a lot*

//I use vim myself.
naris is offline
optimist prime
New Member
Join Date: Oct 2009
Old 10-01-2009 , 23:59   Re: Can't get the example code to compile
Reply With Quote #8

I was using notepad. On my laptop I do my writing in vim but I game on windows so I was sadly without it. What's the advantage of notepad ++ over regular type notepad?
optimist prime is offline
olj
Veteran Member
Join Date: Jun 2009
Old 10-02-2009 , 06:25   Re: Can't get the example code to compile
Reply With Quote #9

Quote:
What's the advantage of notepad ++ over regular type notepad?
This. Dont forget to download notepad++ sourcemod language extension from extensions branch. Nice highlighting (picture is in greyscale though), functions reference, convenient interface etc.
Attached Files
File Type: rar Clipboard01.rar (186.4 KB, 66 views)
__________________
olj is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:47.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode