Loops jumps over number 1
#1

As the title says, my for and while loops jump over 1 at one exact point, when I'm trying to see if a file exists, otherwise my loops does count 1.

Picture of my console where it says which it loads:


An example of a while loop:
Код:
        new x = 0;
	new bizStr[128];
	while(x < maxBusiness)
	{
	    format(bizStr, sizeof(bizStr), BusinessPATH, x);
	    if(fexist(bizStr))
	    {
    		INI_ParseFile(bizStr, "loadbusiness", .bExtra = true, .extra = x);
    		x = CreateDynamicPickup(eStats[x][bizModelID], eStats[x][bizType], eStats[x][bizX], eStats[x][bizY], eStats[x][bizZ], eStats[x][bizVW], eStats[x][bizIW], eStats[x][bizShowTo], eStats[x][bizRange]);
			printf(bizStr);
		}
		x++;
	}
Example of a for loop:
Код:
for(new x; x < maxBusiness; x++)
	{
	    new bizStr[128], lol[10];
	    format(bizStr, sizeof(bizStr), BusinessPATH, x);
	    format(lol, sizeof(lol), "%i", x);
	    printf(lol);
	    if(fexist(bizStr))
	    {
    		INI_ParseFile(bizStr, "loadbusiness", .bExtra = true, .extra = x);
    		x = CreateDynamicPickup(eStats[x][bizModelID], eStats[x][bizType], eStats[x][bizX], eStats[x][bizY], eStats[x][bizZ], eStats[x][bizVW], eStats[x][bizIW], eStats[x][bizShowTo], eStats[x][bizRange]);
			printf(bizStr);
		}

	}
FAQ:
OMG ur using the both variables x two times!!!
- No I am not, I am commenting one of the loops when trying to run the other.

Do you get any errors?
- Nope.

Does everything else work?
- Yes, it loads all the pickups properly BESIDES number 1, and it is always the same story.

Have you tried to only print out X?
- Yes, it jumps over number 1 as long as I have the "if(fexist)" statement inside the loop, otherwise the loops work fine.

Too many tabs somewhere!
- No it isn't, when you copy something like this into a forum it will look stupid.


Additional comment
I hope I provided enough with information haha. :P
Reply
#2

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
- Yes, it jumps over number 1 as long as I have the "if(fexist)" statement inside the loop, otherwise the loops work fine.
So 1.ini file does not exist.
Reply
#3

This code relies on assumptions, which is bad. It assumes that the first pickup to be created will have id 1, while that may not always be the case.

You start with x = 0. CreateDynamicPickup assigns it the value 1. x is then incremented. x is now 2. The next cycle will start with x = 2.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
This code relies on assumptions, which is bad. It assumes that the first pickup to be created will have id 1, while that may not always be the case.

You start with x = 0. CreateDynamicPickup assigns it the value 1. x is then incremented. x is now 2. The next cycle will start with x = 2.
What do you mean assumes to create first pickup to be 1? :O My pickup id's starts with 0. Or maybe they may not do that?

So it's better to not have a 0.ini at all but start the creations at 1 instead in my "createbusiness" command?

EDIT: Understood now. Dynamic starts always with 1 instead of 0. Seems crazy once you've learned that mostly everything in programming starts with 0 but yeah, thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)