SA-MP Forums Archive
for() doesnt work (mysql_tquery) - 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: for() doesnt work (mysql_tquery) (/showthread.php?tid=599262)



for() doesnt work (mysql_tquery) - Aa12 - 23.01.2016

Код:
public OnGameModeInit()
{
mysql_tquery(mysql, "SELECT * FROM houses", "LoadHouse");
return 1;
}

forward LoadHouse();
public LoadHouse()
{
for(new i=1; i<47; i++)
{
printf("%i", i);
}
return 1;
}
what I get printed :
Код:
0
1
2
3
and so on...
Problem is that numbers should start with 1, not with 0... No matter what value I give to "new i" it always starts with zero


Re: for() doesnt work (mysql_tquery) - Prokill911 - 23.01.2016

Lol.
Код:
for(new i=0;i<47;i++) {



Re: for() doesnt work (mysql_tquery) - LetsOWN[PL] - 23.01.2016

Quote:
Originally Posted by Aa12
Посмотреть сообщение
Код:
public OnGameModeInit()
{
mysql_tquery(mysql, "SELECT * FROM houses", "LoadHouse");
return 1;
}

forward LoadHouse();
public LoadHouse()
{
for(new i=1; i<47; i++)
{
printf("%i", i);
}
return 1;
}
what I get printed :
Код:
0
1
2
3
and so on...
Problem is that numbers should start with 1, not with 0... No matter what value I give to "new i" it always starts with zero
Pretty weird.
Maybe try with this 'C' style thing:

pawn Код:
public LoadHouse() {
  new i = 1;
  for(i; i < 47; i++)  printf("%d", i);  
}



Re: for() doesnt work (mysql_tquery) - Aa12 - 23.01.2016

Quote:
Originally Posted by Prokill911
Посмотреть сообщение
Lol.
Код:
for(new i=0;i<47;i++) {
I dont think you understood my problem


Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
Pretty weird.
Maybe try with this 'C' style thing:

pawn Код:
public LoadHouse() {
  new i = 1;
  for(i; i < 47; i++)  printf("%d", i);  
}
Doesnt work, also I get warning
warning 215: expression has no effect


Re: for() doesnt work (mysql_tquery) - amirm3hdi - 23.01.2016

Код:
for (new i = 1; i < MAX_I_VALUES_HERE; i++)
{
    if (!i) continue;
    printf('Looping %i', i);
}
Done


Re: for() doesnt work (mysql_tquery) - LetsOWN[PL] - 23.01.2016

Quote:
Originally Posted by amirm3hdi
Посмотреть сообщение
Код:
for (new i = 1; i < MAX_I_VALUES_HERE; i++)
{
    if (!i) continue;
    printf('Looping %i', i);
}
Done
Skipping i when it's 0 does not make sense.

Quote:

No matter what value I give to "new i" it always starts with zero

What, if i = 10..


Re: for() doesnt work (mysql_tquery) - amirm3hdi - 23.01.2016

Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
Skipping i when it's 0 does not make sense.


What, if i = 10..
You mean even that code doesn't work?


Re: for() doesnt work (mysql_tquery) - LetsOWN[PL] - 23.01.2016

Quote:
Originally Posted by amirm3hdi
Посмотреть сообщение
You mean even that code doesn't work?
I mean your solution does not solve the problem in question.

All your code does is just skip anything in the loop when iterator (i) is equal to 0 (because negation of 0 is 1, so does !i).

The problem is that even for:
for(new i = 5; i < 47; i++)

it will give: 0, 1, 2, 3...

Well, at least that's what this thread is about.


Re: for() doesnt work (mysql_tquery) - amirm3hdi - 23.01.2016

Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
I mean your solution does not solve the problem in question.

All your code does is just skip anything in the loop when iterator (i) is equal to 0 (because negation of 0 is 1, so does !i).

The problem is that even for:
for(new i = 5; i < 47; i++)

it will give: 0, 1, 2, 3...

Well, at least that's what this thread is about.
Well, my solution gives you what you want.. not counting 0,
if you wanna do "new i = 5" then you must do "if (i < 5) continue;"...

Check your recent changes, maybe something messes this up...
I've never seen such problem tho.

You tried while() ?


Re: for() doesnt work (mysql_tquery) - Aa12 - 23.01.2016

Okay guys, so I don't know what happened but now it works, lol. I didn't change anything in the code, but I just tried it again(launch server.exe) couple of times and it worked... Sorry for wasting you time

Thanks for trying to help anyways!

Quote:
Originally Posted by LetsOWN[PL]
Посмотреть сообщение
Skipping i when it's 0 does not make sense.


What, if i = 10..
Before it worked, I set i=8, it still started from zero