const explained please
#1

Hey, I couldn't find a constant on the wiki, what I am actually trying to do is store more coords in same variable if thats how it is called, I know that it looks something like this?:


new x [] =
{ x, y, z}
{ x, y, z}
;

But I don't actually know how to make it properly.
Reply
#2

pawn Код:
static const
        Float:CameraPos[][3] =
    {
        {x, y, z},

    };
Use new if you want to load it in other scripts.


A 'const' is a constant expression that cannot be changed it is faster than normal variables hence they can't change its value.
Reply
#3

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
pawn Код:
static const
        Float:CameraPos[][3] =
    {
        {x, y, z},

    };
Use new if you want to load it in other scripts.
Can you also explain to me what does this number mean? '[3]', do I need to raise it if I want to add more coords?

I want to use it for gas stations, can I just call it like this? if(IsPlayerInRangeOfPoint(playerid, 8.0, CameraPos);

I will change its name so don't bother telling me that xD
Reply
#4

pawn Код:
static const
        Float:CameraPos[][3] =
    {
        0{x0, y1, z2},
                1{x0, y1, z2}
    };
so:

Let's say i want to use the x position from the second row.

CameraPos[1][0]
Reply
#5

You can think of arrays like tables:

One dimension ([]) = number of rows,
Two dimensions ([][]) = number of rows, number of columns (tabular),
Three dimensions ([][][]) = number of tables, number of rows, number of columns.

It is usually not necessary to actually put numbers between the brackets. The compiler can calculate the size.
Reply
#6

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
pawn Код:
static const
        Float:CameraPos[][3] =
    {
        0{x0, y1, z2},
                1{x0, y1, z2}
    };
I mean, this number: Float:CameraPos[][3], do I also have to raise that if I add more coords?
Reply
#7

Yeah, I like to be a smartass and set up a value to keep me reminded that i shouldn't use that value or cross that same value.

You can also use sizeof(CameraPosition) to see the actual size if you need to loop it or just check.


Edit: No you can set it empty and the compiler will itself calculate its size as Vince said.
Reply
#8

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
Yeah, I like to be a smartass and set up a value to keep me reminded that i shouldn't use that value or cross that same value.

You can also use sizeof(CameraPosition) to see the actual size if you need to loop it or just check.


Edit: No you can set it empty and the compiler will itself calculate it's size as Vince said.
I am still not sure how to use it

This doesn't work
PHP код:
CMD:buyfuel(playeridparams)
{
    if(
IsPlayerInRangeOfPoint(playerid13.0GasStations[0], GasStations[1], GasStations[2])
    {
    
    }
    return 
1;

Neither this
PHP код:
CMD:buyfuel(playeridparams)
{
    if(
IsPlayerInRangeOfPoint(playerid13.0GasStations)
    {
    
    }
    return 
1;

Reply
#9

PHP код:
CMD:buyfuel(playeridparams)
{
    if(
IsPlayerInRangeOfPoint(playerid13.0GasStations[0][0], GasStations[0][1], GasStations[0][2])
    {
    
    }
    return 
1;

The first [] is for the row and the second one is for the column.
Reply
#10

Quote:
Originally Posted by Runn3R
Посмотреть сообщение
PHP код:
CMD:buyfuel(playeridparams)
{
    if(
IsPlayerInRangeOfPoint(playerid13.0GasStations[0][0], GasStations[0][1], GasStations[0][2])
    {
    
    }
    return 
1;

The first [] is for the row and the second one is for the column.
Thanks alot, can't rep you again because I did it already but I will do as soon as I can.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)