Array issue.
#1

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;
}
Reply
#2

sizeof(CmdList)
Reply
#3

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.
Reply
#4

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;
}
Reply
#5

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
Reply
#6

it works because its a string
Reply
#7

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)