SA-MP Forums Archive
More efficient way of listitem. - 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: More efficient way of listitem. (/showthread.php?tid=647519)



More efficient way of listitem. - jasperschellekens - 06.01.2018

Hello, I was wondering if there is any easyer/better way to do the following:

PHP код:
 if(listitem == 0)
                        {
                            
format(filesizeof(file), "Data/Reports/r0.ini");
                        }
                        if(
listitem == 1)
                        {
                            
format(filesizeof(file), "Data/Reports/r1.ini");
                        }
                        if(
listitem == 2)
                        {
                            
format(filesizeof(file), "Data/Reports/r2.ini");
                        } 
I did try:
PHP код:
format(filesizeof(file), "Data/Reports/r%d.ini"listitem); 
But sadly that doesn't work. Any other way to this?


Re: More efficient way of listitem. - rfr - 06.01.2018

https://sampwiki.blast.hk/wiki/Control_Structures

Use case for a more efficient way.


Re: More efficient way of listitem. - Jaxson - 06.01.2018

I don't see why would this not work:

pawn Код:
format(file, sizeof(file), "Data/Reports/r%d.ini", listitem);
This is the most efficient way to do that.


Re: More efficient way of listitem. - jasperschellekens - 06.01.2018

Quote:
Originally Posted by Jaxson
Посмотреть сообщение
I don't see why would this not work:

pawn Код:
format(file, sizeof(file), "Data/Reports/r%d.ini", listitem);
This is the most efficient way to do that.
Indeed, thats what i tought but it doesn't work. It shows ID0 always...


Re: More efficient way of listitem. - Kane - 06.01.2018

Debug it, print out the results.


Re: More efficient way of listitem. - jasperschellekens - 06.01.2018

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
Debug it, print out the results.
I'm sorry i don't understand. how do i do that?


Re: More efficient way of listitem. - Kane - 06.01.2018

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
I'm sorry i don't understand. how do i do that?
https://sampwiki.blast.hk/wiki/Printf


Re: More efficient way of listitem. - jasperschellekens - 06.01.2018

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
I do not understand how that printing something on the server log will tell me why listitem does not work.

Could anybody give me an example on using this with switch case?


Re: More efficient way of listitem. - adri1 - 06.01.2018

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
I do not understand how that printing something on the server log will tell me why listitem does not work.

Could anybody give me an example on using this with switch case?
https://sampwiki.blast.hk/wiki/Debugging


Re: More efficient way of listitem. - jasperschellekens - 06.01.2018

I did something wrong after all, now it is working fine. thanks for the help.

I have one more question.
How to check if an array is equal to playername?

This does not work:

PHP код:
if(ReportInfo[repid][ReportOpenedBy] == GetPlayerName(playerid);) 
This also does not work:

PHP код:
TempReportNameCheck[playerid] = GetPlayerName(playerid);
if(
ReportInfo[repid][ReportOpenedBy] == TempReportNameCheck[playerid])