PDA

View Full Version : Call all arrays in one


coool
11/12/2016, 06:29 AM
Yes, whether my title is expressing or not let me tell you my problem..
I have arranged arrays like this
new veh[2] =
{ 400, 401 };

And now how can I call this 2 variable in one arrary for example
if(GetVehicleModel(vmodel) == veh[2]) //the veh[2] will call only the number 401
Now tell how to call the 2 variable in one.

AjaxM
11/12/2016, 06:38 AM
new veh[2] =
{ 400, 401 };

for(new i; i < sizeof(veh); i++)
{
if(GetVehicleModel(vmodel) == veh[i])
}


Try this.

EDIT ; Yes, i forgot the i.

coool
11/12/2016, 06:46 AM
Similar but not the same

new veh[2] =
{ 400, 401 };

for(new i; i < sizeof(veh); i++)
{
if(GetVehicleModel(vmodel) == veh[i]) //You should index an i inside.
}

BiosMarcel
11/12/2016, 11:10 AM
new veh[2] =
{ 400, 401 };


There is too ways, depending on the size of the arrays you have to decide, but if the arrays size often changes, i recommend way 1

for(new i; i < sizeof(veh); i++)
{
if(GetVehicleModel(vmodel) == veh[i])
{
new modelText[30];
format(modelText, 30, "The Vehicle model is: %d", veh[i]);
printf("%s", modelText);
return 1;
}
}


or

if(GetVehicleModel(vmodel) == veh[0] || GetVehicleModel(vmodel) == veh[1])
{
return 1;
}

and also

if(GetVehicleModel(vmodel) == veh[2]) //the veh[2] will call only the number 401

this would give you an out of bounds error, because max index is "1".

coool
11/12/2016, 11:24 AM
You said: or

if(GetVehicleModel(vmodel) == veh[0] || GetVehicleModel(vmodel) == veh[1])
{
return 1;
}

But it is a timy work.
And can this also work
if(GetVehicleModel(vmodel) == veh[0 || 1])
{
return 1;
}

BiosMarcel
11/12/2016, 11:28 AM
You said: or

if(GetVehicleModel(vmodel) == veh[0] || GetVehicleModel(vmodel) == veh[1])
{
return 1;
}

But it is a timy work.
And can this also work

if(GetVehicleModel(vmodel) == veh[0 || 1])
{
return 1;
}


1. what does "timy work" mean (Edit: ah, you meant tiny)
2. no, that "veh[0 || 1]" is not valid syntax

Logic_
11/12/2016, 11:34 AM
Having no or very little amount of knowledge about SA-MP scripting and you are arguing or representing invalid/ non-existent methods/ syntax...

You better put some time into SA-MP scripting Wiki before posting something like that, programming/ scripting is based on LOGIC.

BiosMarcel
11/12/2016, 11:34 AM
Having no or very little amount of knowledge about SA-MP scripting and you are arguing or representing invalid/ non-existent methods/ syntax...

Explain

Sorry if i was wrong, i was sure it doesn't work

Forgive me :D

Logic_
11/12/2016, 11:36 AM
Marcel;3811985']Explain

Not you, talking about the other guy.