Raised This Month: $32 Target: $400
 8% 

SourcePawn "Action:" what is it?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
test3
Junior Member
Join Date: May 2012
Old 05-09-2012 , 08:47   SourcePawn "Action:" what is it?
Reply With Quote #1

Hello,
English is not my first language, that why it will have errors and I'll try to do my best.

I already know how code in php, a little bit in C, 2 years ago with the pascal and Visual Basic (but I still have some difficulties with functions), I started to learn the sourcepawn since some days.

I read that page: http://wiki.alliedmods.net/Introduct...ns#Declaration
And I don't really understand what does this code below:
Code:
public Action:Command_MySlap(client, args) { }
It's a function of course, but what is the text "Action:", I saw that was a tag, like the tags in HTML like "<a>" for a link ? My translation must be wrong...

The second question is about the parameters of this function: Is an obligation to name the first parameter "client" and the second "args" ?
I guess not, and I think we can do a function like:
Code:
public Action:Command_MySlap(arguments, client) { }

Adjust the parameter 'arguments' in the function.
And after the compilation, write in the console: sm_myslap [number of damages] [the name of the client].

It's the first time that I read a tutorial for programming in english and I feel to don't know what I'm doing :/

Good afternoon.
test3 is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 05-09-2012 , 09:19   Re: SourcePawn "Action:" what is it?
Reply With Quote #2

no, you can't
it's a defined function structure
that calls when called registered command
"Action:" because it's an action. it can be passes without changes, can be changed, or even prevented/blocked.
you can replace (client, args) with (args, client), but it make code harder to read, also you must keep in mind that first param is a client id and second - number of arguments.
__________________
Leonardo is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 05-09-2012 , 15:25   Re: SourcePawn "Action:" what is it?
Reply With Quote #3

The order of parameters is very important, as the Pawn runtime is not aware of the names used, that's like in C too. And pawn is very similar to C.

There is no equivalent for Pawn Tags (enums) in HTML.
If Pawn would have classes, the HTML <a> Tag would be a classname in Pawn

The enum Action is defined like this in core.inc:

PHP Code:
/**
 * Specifies what to do after a hook completes.
 */
enum Action
{
    
Plugin_Continue 0,    /**< Continue with the original action */
    
Plugin_Changed 1,        /**< Inputs or outputs have been overridden with new values */
    
Plugin_Handled 3,        /**< Handle the action at the end (don't call it) */
    
Plugin_Stop 4,        /**< Immediately stop the hook chain and handle the original */
}; 
You see it's a kind of pseudo datatype, an enum.

An enum is a list of possible values. Only one of them can be used as return value in a function or when used with a variable.

ie.: return Plugin_Handled;

It's a good way to not having to deal with plain numbers, but named values.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0

Last edited by berni; 05-09-2012 at 15:26.
berni is offline
test3
Junior Member
Join Date: May 2012
Old 05-09-2012 , 16:00   Re: SourcePawn "Action:" what is it?
Reply With Quote #4

Thank you very much Leonardo and berni,

Maybe is a better idea to continue to learn the language C ? What is the differences with a high-level programming language (PHP as example), etc. Or is it not so hard that I believe ? If it's a better idea to know completly how work the language C, it's not necessary to respond to my questions below.

EDIT: Infact, I think it's a good idea to learn how code with the language C, that will be easier later to code with Sourcepawn. Do I need to edit the main title and put "[solved]" or something else ?

Quote:
but I have some other problems, I'll explain how I see the code below.

The function OnPluginStart() creates a consol command, the string that we need to write in the consol is "sm_myslap" and the user writes the name of the client and the damages (like: "sm_MySlap [name of the client] [damages]" ).
When this command is invoked, the function "Command_MySlap" is used. The last parameter is an administrative flag, but I don't know what do this flag and what are the others (how to know all of them) ?.

When the function Command_MySlap() is invoked, there is 2 arguments: "client" and "args". But where are they from ? An argument must be an input, so how it takes the client name and the damages ?

Then I don't understand what is the utility to know how many arguments are in the function ? What is the purpose of this argument ?

And finaly, the purpose of the exercice/example is to create a command where we can slap a player, so we write in the console "sm_MySlap [name of the client] [damages]", but where can we take those informations, put them in the function Command_MySlap() ?

I think I didn't really understand what is a callback function and how it works.

Code:
public OnPluginStart()
{
	RegAdminCmd("sm_myslap", Command_MySlap, ADMFLAG_SLAY)
}
 
public Action:Command_MySlap(client, args)
{
[...]

Last edited by test3; 05-09-2012 at 16:07.
test3 is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 05-09-2012 , 16:14   Re: SourcePawn "Action:" what is it?
Reply With Quote #5

why no just read wiki?

Quote:
Originally Posted by test3 View Post
Do I need to edit the main title and put "[solved]" or something else ?
if you want.
__________________
Leonardo is offline
test3
Junior Member
Join Date: May 2012
Old 05-09-2012 , 16:32   Re: SourcePawn "Action:" what is it?
Reply With Quote #6

I already read it, but some points are complicated, I didn't understand all the things, understand a new informatic language in my first language is already complicate, but do it in english is really hard, that why I'll read how code with C. Thank you again for the help.

And apart form the main subject, How was my english ? A lot of errors, good, bad ? I hop that wasn't too bad.

Good night.
test3 is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 05-09-2012 , 16:39   Re: SourcePawn "Action:" what is it?
Reply With Quote #7

Well, Sourcepawn is quite easier to learn in my opinion, because it doesn't have that many language constructs like C does.
I recommend reading the source code of other people's plugin, that really helps, but don't takeover everything, there are really bad coded plugins out there.

Quote:
Originally Posted by test3 View Post
How was my english ? A lot of errors, good, bad ? I hop that wasn't too bad
Your English is better than the English of 80% of the people writing in this forum
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 05-09-2012 , 16:40   Re: SourcePawn "Action:" what is it?
Reply With Quote #8

most of functions' names are based on english words to clearly understand what they're means/doing.
so it'll be better to know english.

too bad it's not my native lahguage too :c

Last edited by Leonardo; 05-09-2012 at 16:42.
Leonardo is offline
test3
Junior Member
Join Date: May 2012
Old 05-09-2012 , 17:05   Re: SourcePawn "Action:" what is it?
Reply With Quote #9

Yeah, and I prefer to know how code with a tutorial of informatic language than search in a program with a lot of plugins, etc. (It's just my opinion :p)

Well, thank you for you two to had helped me.
test3 is offline
Sillium
AlliedModders Donor
Join Date: Sep 2008
Location: Germany
Old 05-10-2012 , 01:15   Re: SourcePawn "Action:" what is it?
Reply With Quote #10

You can also read the Pawn documentation:
http://www.compuphase.com/pawn/pawn.htm#DOWNLOAD_DOCS
__________________
brb, dishes have developed their own language and are talking to the garbage about overthrowing me... i must correct this

www.unterwasserpyromanen.de

Last edited by Sillium; 05-10-2012 at 01:15.
Sillium 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 16:22.


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