More efficient way of listitem.
#1

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?
Reply
#2

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

Use case for a more efficient way.
Reply
#3

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.
Reply
#4

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...
Reply
#5

Debug it, print out the results.
Reply
#6

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

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

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?
Reply
#9

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
Reply
#10

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]) 
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)