SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 06/01/2018, 09:12 AM   #1
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 686
Reputation: 43
Default More efficient way of listitem.

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

PHP Code:
 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 Code:
format(filesizeof(file), "Data/Reports/r%d.ini"listitem); 
But sadly that doesn't work. Any other way to this?
jasperschellekens is offline   Reply With Quote
Old 06/01/2018, 09:16 AM   #2
rfr
Banned
 
Join Date: Nov 2017
Posts: 306
Reputation: 43
Default Re: More efficient way of listitem.

http://wiki.sa-mp.com/wiki/Control_Structures

Use case for a more efficient way.
rfr is offline   Reply With Quote
Old 06/01/2018, 09:21 AM   #3
Jaxson
Big Clucker
 
Jaxson's Avatar
 
Join Date: Oct 2010
Location: Croatia
Posts: 141
Reputation: 65
Default Re: More efficient way of listitem.

I don't see why would this not work:

Code:
format(file, sizeof(file), "Data/Reports/r%d.ini", listitem);

This is the most efficient way to do that.
__________________
185.34.216.79:7777
Jaxson is offline   Reply With Quote
Old 06/01/2018, 09:22 AM   #4
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 686
Reputation: 43
Default Re: More efficient way of listitem.

Quote:
Originally Posted by Jaxson View Post
I don't see why would this not work:

Code:
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...
jasperschellekens is offline   Reply With Quote
Old 06/01/2018, 09:34 AM   #5
Arthur Kane
Gangsta
 
Join Date: Sep 2012
Posts: 772
Reputation: 115
Default Re: More efficient way of listitem.

Debug it, print out the results.
__________________
LS:RP Development Team
Arthur Kane is offline   Reply With Quote
Old 06/01/2018, 09:37 AM   #6
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 686
Reputation: 43
Default Re: More efficient way of listitem.

Quote:
Originally Posted by Arthur Kane View Post
Debug it, print out the results.
I'm sorry i don't understand. how do i do that?
jasperschellekens is offline   Reply With Quote
Old 06/01/2018, 09:38 AM   #7
Arthur Kane
Gangsta
 
Join Date: Sep 2012
Posts: 772
Reputation: 115
Default Re: More efficient way of listitem.

Quote:
Originally Posted by jasperschellekens View Post
I'm sorry i don't understand. how do i do that?
http://wiki.sa-mp.com/wiki/Printf
__________________
LS:RP Development Team
Arthur Kane is offline   Reply With Quote
Old 06/01/2018, 09:53 AM   #8
jasperschellekens
Gangsta
 
jasperschellekens's Avatar
 
Join Date: Dec 2016
Location: Gehenna
Posts: 686
Reputation: 43
Default Re: More efficient way of listitem.

Quote:
Originally Posted by Arthur Kane View Post
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?
jasperschellekens is offline   Reply With Quote
Old 06/01/2018, 10:06 AM   #9
[HLF]Southclaw
High-roller
 
[HLF]Southclaw's Avatar
 
Join Date: Apr 2009
Location: England
Posts: 4,919
Reputation: 1460
Default Re: More efficient way of listitem.

format is the way to go, that *will* work, %d is for integers and listitem is an integer.

You haven't really specified what's not working about this. Arthur was referring to printing out the result of `file` after you format it to see what the actual value is in case you've missed something.
__________________
Tools:

Plugins:

Links:

[HLF]Southclaw is online now   Reply With Quote
Old 06/01/2018, 10:10 AM   #10
adri1
Banned
 
Join Date: Oct 2010
Posts: 1,938
Reputation: 955
Default Re: More efficient way of listitem.

Quote:
Originally Posted by jasperschellekens View Post
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?
http://wiki.sa-mp.com/wiki/Debugging
adri1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help about listitem Sensation Scripting Help 17 19/09/2015 12:19 PM
Listitem Help. Prokill911 Scripting Help 2 17/02/2015 04:31 PM
[Ajuda] Listitem Tugamars Português/Portuguese 3 16/02/2015 11:44 PM
Getting the name of listitem Nimrodcame General 5 16/05/2013 07:28 PM
Listitem. MagicznyKacper Scripting Help 7 28/12/2012 07:44 PM


All times are GMT. The time now is 08:58 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.