SA-MP Forums Archive
probelm with foreach +Repp - 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: probelm with foreach +Repp (/showthread.php?tid=587320)



probelm with foreach +Repp - khRamin78 - 29.08.2015

sry guys but why this happeing for me ?

Код:
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 017: undefined symbol "foreach"
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 029: invalid expression, assumed zero
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 017: undefined symbol "i"
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : fatal error 107: too many error messages on one line
And This Is The Line's :

PHP код:
//This Is Line 2812  if(listitem == 0) {foreach(new i : Player)if(IsPlayerConnected(i))SetPlayerTime(i,7,0);}
               
if(listitem == 1) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,12,0);}
               if(
listitem == 2) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,16,0);}
               if(
listitem == 3) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,20,0);}
               if(
listitem == 4) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,0,0); } 



Re: probelm with foreach +Repp - Ahmad45123 - 29.08.2015

Quote:
Originally Posted by khRamin78
Посмотреть сообщение
sry guys but why this happeing for me ?

Код:
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 017: undefined symbol "foreach"
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 029: invalid expression, assumed zero
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 017: undefined symbol "i"
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : fatal error 107: too many error messages on one line
And This Is The Line's :

PHP код:
//This Is Line 2812  if(listitem == 0) {foreach(new i : Player)if(IsPlayerConnected(i))SetPlayerTime(i,7,0);}
               
if(listitem == 1) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,12,0);}
               if(
listitem == 2) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,16,0);}
               if(
listitem == 3) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,20,0);}
               if(
listitem == 4) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,0,0); } 
You don't have to do IsPlayerConnected.. foreach does that for you..
And also try making ur code more readable, Like:
PHP код:
new time;
switch(
listitem)
{
    case 
0time 7;
    case 
1time 12;
    case 
2time 16;
    case 
3time 20;
    case 
4time 0;
}
foreach(new 
PlayerSetPlayerTime(playeridtime0); 



Re: probelm with foreach +Repp - Logofero - 29.08.2015

Quote:
Originally Posted by khRamin78
Посмотреть сообщение
sry guys but why this happeing for me ?

Код:
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 017: undefined symbol "foreach"
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 029: invalid expression, assumed zero
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : error 017: undefined symbol "i"
C:\Users\KaTA\Desktop\samp training\Test\gamemodes\Test.pwn(2812) : fatal error 107: too many error messages on one line
And This Is The Line's :

PHP код:
//This Is Line 2812  if(listitem == 0) {foreach(new i : Player)if(IsPlayerConnected(i))SetPlayerTime(i,7,0);}
               
if(listitem == 1) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,12,0);}
               if(
listitem == 2) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,16,0);}
               if(
listitem == 3) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,20,0);}
               if(
listitem == 4) {foreach(new Player)if(IsPlayerConnected(i))SetPlayerTime(i,0,0); } 
PHP код:
 if(listitem == 1) {
      foreach(new 
Player) { // <- Add it {
         
if(IsPlayerConnected(i)) SetPlayerTime(i,12,0);
      }

Note: In cycles "for, while" it is always better to put {. Example: for () { ... }


Re: probelm with foreach +Repp - khRamin78 - 29.08.2015

Thanks Both For Your Fast Help's But Still Giving That Error's


Re: probelm with foreach +Repp - jlalt - 29.08.2015

PHP код:
#include a_samp
#include foreach
#define mydialog 6935
  
  
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
     if(
dialogid == mydialog)
        {
        if(
response)
                {
          new 
time;
          switch(
listitem)
          {
          case 
0time 7;
          case 
1time 12;
          case 
2time 16;
          case 
3time 20;
          case 
4time 0;
          }
          foreach(new 
PlayerSetPlayerTime(playeridtime0);
        }
     }
     return 
1;
 } 



Re: probelm with foreach +Repp - Ahmad45123 - 29.08.2015

Do you have y_iterate installed ?


Re: probelm with foreach +Repp - Crayder - 29.08.2015

If you have YSI then just add the following line in your includes:
pawn Код:
#include <YSI\y_iterate>
If you don't have YSI, get it then add the line above.


Re: probelm with foreach +Repp - khRamin78 - 30.08.2015

i just download that foreach and it worked :S

Thanks all for help


Re: probelm with foreach +Repp - Crayder - 30.08.2015

Quote:
Originally Posted by khRamin78
Посмотреть сообщение
i just download that foreach and it worked :S

Thanks all for help
Which one? If you chose the standalone you should really look into YSI. The latest y_iterate (which is the better version of foreach) is a lot better and contains a lot of new features.