• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] how to load every user.ini in scriptfiles using YINI
#32
(2021-02-16, 06:01 AM)Kwarde Wrote:
Quote:you should remove return statement in loop because it stops the loop.
Not just the loop, though. Allow me to add this information for mems:
- "continue" stops the current iteration of the loop and goes to the next iteration (iteration is the right word, right?)
- "break" stops the current iteration and does not go to the next one: "break"ing the loop
- "return" stops the execution of the entire function (so everything after "return" would never run), and if something is specified (a return value) it returns that value to the calling function (if any).

Example using continue:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) continue;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2
4
5
This must be printed!

Example using break:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) break;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2
This must be printed!

Example using return:
Code:
Foo()
{
    for (new i = 1; i <= 5; i)
    {
        if (i == 3) return;
        printf("i=%i", i);
    }
    print("This must be printed!");
}
Output would be:
Quote:1
2


I've seen beginners misusing this quite some times, hence this information examples.

yep, i took care of them now and everything works good so far. now i know a bit more about loops than i did before.

edit: i ended up using a method which really helps with this situation which is counting how many players there are with gsf level. if that count was 0, then i sent the "no account has gsflevel" message. this is how it looks now:

Code:
CMD:osetallgsf(playerid, params[])
{
    new File: handle = fopen("allusers.txt", io_read), nick[MAX_PLAYER_NAME], INI: file;
    new string[192], fstring[46], pname[MAX_PLAYER_NAME], gsflevel, count;
    GetPlayerName(playerid, pname, sizeof(pname));
    if((IsPlayerAdmin(playerid)) || PlayerInfo[playerid][AdminLevel] == 3) {
        if(sscanf(params, "i", gsflevel)) return SendClientMessage(playerid, COLOR_RED, "Syntax: /osetallgsf <level>");
        if(gsflevel > 13) return SendClientMessage(playerid, COLOR_RED, "ERROR: Max GSF level is 13");
        if(gsflevel < 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: Cannot set lower than 0");
        if(handle) {
            while(fread(handle, nick)) {
                StripNewLine(nick);
                format(fstring, 46, "Users/%s.ini", nick);
                if(INI_ParseFile(fstring, "LoadGSFLevel", .bPassTag = true)) {
                    if(GSFLevelInfo > 0 && !onlineinfo) {
                        流⺞;
                        format(string, sizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i.", nick, gsflevel);
                        SendClientMessage(playerid, COLOR_WHITE, string);
                        file = INI_Open(fstring);
                        INI_SetTag(file, "=|PlayerData|=");
                        INI_WriteInt(file, "GSFLevel", gsflevel);
                        INI_Close(file);
                    }
                }
            }
              if(count == 0) {
                SendClientMessage(playerid, COLOR_RED, "ERROR: No account was found having a GSF level.");
                return 1;
            }
            format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);
            SendToRCON(COLOR_AQUA, string);
            fclose(handle);
        } else return SendClientMessage(playerid, COLOR_RED, "ERROR: The file \"allusers.txt\" does not exist, therefore canceling the process.");
        return 1;
    } else return SendClientMessage(playerid, COLOR_RED, "ERROR: Authorization revoked.");
}

not a problem or anything (so far), just for anyone who might have a problem like this. i just wish this
Code:
            format(string, sizeof(string), "[STAFF]: \"%s\" has issued the command: {FF0000}OSETALLGSF{00FFFF}.", pname);
            SendToRCON(COLOR_AQUA, string);
was above this:
Code:
        format(string, sizeof(string), "[{FF0000}GSF{FFFFFF}]: Successfully offline set {FF0000}%s's{FFFFFF} GSF level to: %i.", nick, gsflevel);
                        SendClientMessage(playerid, COLOR_WHITE, string);
which is possible but if the counter finds 0, it will still send the rcon msg with the error msg that it didn't find any player, idk but that looks so weird and wrong to me. but it's okay since only for rcon peeps lol
  Reply


Messages In This Thread
RE: how to load every user.ini in scriptfiles using YINI - by mems - 2021-02-16, 02:42 PM

Forum Jump: