Vector implementation in PAWN -
BigETI - 16.07.2018
Vector implementation in PAWN
Description
This is a vector data structure implementation in PAWN.
Project
The source code and documentation are located at GitHub: https://github.com/BigETI/pawn-vector
Re: Vector implementation in PAWN -
TroS - 16.07.2018
Good job!
Re: Vector implementation in PAWN -
BigETI - 19.07.2018
Quote:
Originally Posted by TroS
Good job!
|
Quote:
Originally Posted by [HLF]Southclaw
Finally, my favourite data structure! (sorry, unsorted_map)
|
thank you
Re: Vector implementation in PAWN -
TommyB - 19.07.2018
BigETI making PAWN slightly more bearable one include at a time. :^)
Re: Vector implementation in PAWN -
BigETI - 19.07.2018
Quote:
Originally Posted by TommyB
BigETI making PAWN slightly more bearable one include at a time. :^)
|
thank brother <3
Re: Vector implementation in PAWN -
iLearner - 19.07.2018
Mashallah
Re: Vector implementation in PAWN -
CodeStyle175 - 19.07.2018
for what system its useful in samp, because samp is so basic
and i really doubt that code written in pawn, does the same level things as other programming languages.
Re: Vector implementation in PAWN -
GhostHacker9 - 19.07.2018
Quote:
Originally Posted by CodeStyle175
for what system its useful in samp, because samp is so basic
and i really doubt that code written in pawn, does the same level things as other programming languages.
|
what you trying to say?
Re: Vector implementation in PAWN -
Calisthenics - 12.10.2018
Very useful include. I can use it as a stack for a non-recursive backtracking.
For anyone interested, I needed a random shuffle for one of my vectors. It is based on Fisher-Yates's algorithm (modern version):
pawn Code:
VECTOR_random_shuffle(Vector: vector, first, last)
{
for (new i = (last - first) - 1; i > 0; --i)
{
VECTOR_swap(vector, i, random(i + 1));
}
}
VECTOR_swap(Vector: vector, a, b)
{
new a_value = VECTOR_get_val(vector, a);
VECTOR_set_val(vector, a, VECTOR_get_val(vector, b));
VECTOR_set_val(vector, b, a_value);
}
pawn Code:
// Example:
public OnGameModeInit()
{
new Vector: vector;
for (new i = 1; i <= 10; i++)
{
VECTOR_push_back_val(vector, i);
}
VECTOR_random_shuffle(vector, 0, VECTOR_size(vector));
VECTOR_foreach(v : vector)
{
printf("%d", MEM_get_val(v));
}
return 1;
}
Although it is still random shuffle, I prefer using MerRandom plugin.
Re: Vector implementation in PAWN -
2Col - 27.10.2018
Is it possible to set float values?
Re: Vector implementation in PAWN -
BigETI - 27.10.2018
Quote:
Originally Posted by 2Col
Is it possible to set float values?
|
anything
Re: Vector implementation in PAWN -
2Col - 27.10.2018
Thanks. And is it possible to set array like this?
Код:
enum PlayerEnum
{
id,
Float:health,
Float:armour
}
new PlayerData[][PlayerEnum] =
{
{1, 2.0, 3.0},
{4, 5.0, 6.0}
};
new Vector:PlayerVector;
for(new i = 0; i < sizeof(PlayerData); i += 1)
{
VECTOR_push_back_arr(PlayerVector, PlayerData[i]);
}
If I try to compile this code, I get this warning:
Код:
warning 229: index tag mismatch (symbol "PlayerData"): expected tag none ("_"), but found "PlayerEnum"
Re: Vector implementation in PAWN -
BigETI - 27.10.2018
enum adds a tag to your variable, so you should just disable that tag either at the enumerator with
or inside the function with
pawn Код:
VECTOR_push_back_arr(PlayerVector, _:PlayerData[i]);
Re: Vector implementation in PAWN -
2Col - 27.10.2018
Thanks. Great include.
Re: Vector implementation in PAWN -
d3Pedro - 27.10.2018
Awesome! Thank you!
Re: Vector implementation in PAWN -
2Col - 11.11.2018
Sorry for bothering you, but I have another question.
Код:
enum PlayerEnum
{
id,
Float:health,
Float:armour
}
new Vector:PlayerVector[PlayerEnum];
VECTOR_push_back_val(PlayerVector[id], 0);
VECTOR_push_back_val(PlayerVector[health], 0.0);
VECTOR_push_back_val(PlayerVector[armour], 0.0);
Код:
warning 213: tag mismatch: expected tag "Vector", but found none ("_")
warning 213: tag mismatch: expected tag "Vector", but found "Float"
warning 213: tag mismatch: expected tag none ("_"), but found "Float"
warning 213: tag mismatch: expected tag "Vector", but found "Float"
warning 213: tag mismatch: expected tag none ("_"), but found "Float"
Is this the correct way to fix this?
Код:
enum PlayerEnum
{
id,
Float:health,
Float:armour
}
new Vector:PlayerVector[PlayerEnum];
VECTOR_push_back_val(Vector:PlayerVector[id], 0);
VECTOR_push_back_val(Vector:PlayerVector[health], _:0.0);
VECTOR_push_back_val(Vector:PlayerVector[armour], _:0.0);
Re: Vector implementation in PAWN -
BigETI - 11.11.2018
What are you even trying to do?
Re: Vector implementation in PAWN -
2Col - 12.11.2018
Quote:
Originally Posted by BigETI
What are you even trying to do?
|
Something like this, but I want to use enums for more readable code.
Код:
new Vector:PlayerVector[3];
VECTOR_push_back_val(PlayerVector[0], 0);
VECTOR_push_back_val(PlayerVector[1], _:0.0);
VECTOR_push_back_val(PlayerVector[2], _:0.0);
Re: Vector implementation in PAWN -
BigETI - 12.11.2018
Are you trying to push player data into a single vector or are you trying to structurize single player data as a vector?
Re: Vector implementation in PAWN -
2Col - 12.11.2018
Quote:
Originally Posted by BigETI
Are you trying to push player data into a single vector or are you trying to structurize single player data as a vector?
|
Structurize.