Maybe it's the most convenient syntax for pawn -
a3om - 14.02.2014
During my work in SA:MP I have developed I think a lot of useful things. And this is one of them.
You know, for example you can write this:
PHP Code:
public OnPlayerConnect(playerid)
{
Player[playerid][Player_Connected] = true;
Player[playerid][Player_Money] = 1000;
SetPlayerPos(playerid, 0.0, 0.0, 0.0);
}
But I suggest you write this:
PHP Code:
public OnPlayerConnect(player)
{
Player.Connected = true;
Player.Money = 1000;
player.SetPos(0.0, 0.0, 0.0);
}
I know, it looks strange. But can you imagine how convenient it is? And fortunately it's possible. I think it will save your time because you will write less. I should add that this is not all. If you like this trend, I'll tell all my ideas about it and show how they can be implemented.
Thank you.
Re: Maybe it's the most convenient syntax for pawn -
Ada32 - 14.02.2014
i'm looking at you're catalog and it's empty..
anyway, how is this convenient?
Re: Maybe it's the most convenient syntax for pawn -
a3om - 14.02.2014
Yes, you're right, I don't often write in our forum.
If you have a large amount of code in your gamemode it's much easier and readable I think. Also you print a lot less characters. This reduces the number of unnecessary operations and makes sense to concentrate on.
Re: Maybe it's the most convenient syntax for pawn -
AlonzoTorres - 14.02.2014
That's called object-oriented scripting. In this case the object would be the player.
Re: Maybe it's the most convenient syntax for pawn -
a3om - 14.02.2014
I'm very glad you think so, but it's only implemented in usual Pawn and it only looks like object-oriented scripting
Re: Maybe it's the most convenient syntax for pawn -
AlonzoTorres - 14.02.2014
Quote:
Originally Posted by a3om
I'm very glad you think so, but it's only implemented in usual Pawn and it only looks like object-oriented scripting 
|
Yes that's what I meant.
Re: Maybe it's the most convenient syntax for pawn -
Ada32 - 14.02.2014
Quote:
Originally Posted by a3om
If you have a large amount of code in your gamemode it's much easier and readable I think. Also you print a lot less characters. This reduces the number of unnecessary operations and makes sense to concentrate on.
|
that's a rather poor argument.. but anyways, if you're trying to push for a pseudo class-like structure (that's actually far beneath the intended purpose) and group 32-bit blocks then it's essentially the same as using arrays :\.
-
a3om - 14.02.2014
Hm... Don't get me wrong, but I don't want to change the structure of the programming language. I just want to make the syntax more convenient.
I do this because in our code has a lot of repetitive places. Look at this:
PHP Code:
public OnPlayerConnect(playerid)
{
SomePlayerFunction1(playerid, ...); // the first repetition
SomePlayerFunction2(playerid, ...); // the second
SomePlayerFunction3(playerid, ...); // the third
...
// And there is more
}
Obviously, all this code we are talking about one player. Why not simplify it?
PHP Code:
public OnPlayerConnect(player) // playerid -> player
{
player.SomeFunction1(...);
player.SomeFunction2(...);
player.SomeFunction3(...);
...
}
Looks nice, does not it?
And look at this:
PHP Code:
players.for
{
if(!player.IsConnect()) // or !Player.Connected
{
continue;
}
player.Kick("You're a cheater!");
}
It's very simple.
And this is a loop through all connected players:
PHP Code:
players.connected
{
player.SetVelocity(0.0, 0.0, 1.0);
// or
Player.Velocity.X = 0.0;
Player.Velocity.Y = 0.0;
Player.Velocity.Z = 1.0;
player.SetVelocity();
}
This is the normal loop:
PHP Code:
for(i -> 10) // this is equivalent to: for(new i = 0; i < 10; ++i)
{
// something there
}
Re: Maybe it's the most convenient syntax for pawn -
Ada32 - 14.02.2014
what?
someplayerfunction 1, 2 and 3 obviously do something. so how is it repetitive to make calls to functions that do something
anyway, how are you planning on implementing this?
edit
judging by that^ post, you're goal is to emulate objects in pawn (so its much more than a syntax change). y_less had a topic on oo (i'll see if i can find it) and you should probably contribute your ideas there..
-
a3om - 14.02.2014
I have already implemented and used it in my designs. It very helps me because it's simple.
Of course, these functions do something. Buy I have meant that "Put
PlayerInVehicle(
playerid, vehicleid, 0) is a repetition. Why write it twice?
Yes, I would gladly
It's not an object-oriented approach. It's likely to system-object-oriented approach. There is a system (such as "players") and there are objects (such as "player") in it. It's simple and clear.