Array issue. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Array issue. (
/showthread.php?tid=444073)
Array issue. -
kin - 15.06.2013
I have a very vague understanding of Array's because I just started programming in PAWN again. I have been off doing languages such as Java. Any ways, I'm trying to make an array of Text that will be randomly blurted out over the servers chat. Now when I try and iterate through the array I find myself not knowing how many elements are in it, therefore I cannot tell the code when to stop iterating.
Here is my code currently, with the array present:
pawn Код:
new CmdList[3] = {
"{FFBF00}--------------------------------------------------",
"{FFBF00}/©reatehouse - Displays the house creation dialog",
"{FFBF00}--------------------------------------------------",
;
public OnFilterScriptInit(){
print("| RHousing Version: 1.0 |");
for (new i = 0; i>=0; i++){
if (CmdList[i] != 0){
print("yay");
}
}
return 1;
}
Re: Array issue. -
mastermax7777 - 15.06.2013
sizeof(CmdList)
Re: Array issue. -
Ballu Miaa - 15.06.2013
Quote:
Originally Posted by mastermax7777
sizeof(CmdList)
|
I think this is how you wanted it to do it. The loop will stop at the end element of your array.
pawn Код:
public OnFilterScriptInit()
{
print("| RHousing Version: 1.0 |");
for (new i = 0; i >= sizeof(CmdList); i++)
{
if (CmdList[i] != 0)
{
print("yay");
}
}
return 1;
}
Rep+4 for the attempt to learn.
Re: Array issue. -
kin - 15.06.2013
I figured it out haha, sorry for wasting your time. I read the
Beginner's Guide: Single/Two/Multi-dimensional Arrays guide and figured out that I needed to use a multi-array and iterate through the different arrays inside of it. The code is below for documentation purposes.
pawn Код:
new CmdList[][] = {
"{FFBF00}--------------------------------------------------",
"{FFBF00}/©reatehouse - Displays the house creation dialog",
"{FFBF00}/©reatehouse - Displays the house creation dialog",
"{FFBF00}/©reatehouse - Displays the house creation dialog",
"{FFBF00}/©reatehouse - Displays the house creation dialog",
"{FFBF00}--------------------------------------------------"
};
public OnFilterScriptInit(){
print("| RHousing Version: 1.0 |");
for (new i = 0; i<sizeof(CmdList); i++){
print(CmdList[i][0]);
}
return 1;
}
Re: Array issue. -
Niko_boy - 15.06.2013
print(CmdList[i][0]);
does this even worked? i doubt so
anyways this should too do the job print(CmdList[i]);// will print i'th element of array
Re: Array issue. -
mastermax7777 - 15.06.2013
it works because its a string
Re: Array issue. -
KingHual - 15.06.2013
Quote:
Originally Posted by Niko_boy
print(CmdList[i][0]);
does this even worked? i doubt so
|
It works.
Код:
print(CmdList[i][6]);
would be a substring of CmdList[i], printing every character after the 6th one until it hits a null character.