Raised This Month: $52 Target: $400
 13% 

Solved Read file backwards


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 10-15-2019 , 14:34   Read file backwards
Reply With Quote #1

Hello AM, I populate a menu with data from an .ini file, however, I would like to populate the menu with data from Back to Front (newer to older), but I found nothing about...

Thanks.
__________________

Last edited by iceeedr; 10-17-2019 at 07:33.
iceeedr is offline
Send a message via Skype™ to iceeedr
JocAnis
Veteran Member
Join Date: Jun 2010
Old 10-15-2019 , 14:59   Re: Read file backwards
Reply With Quote #2

store all lines into array, then add all items from the array from the LAST added, going descending...? you will know that to make bro
__________________
KZ Public Autocup
PrimeKZ


My blog:
http://primekz.xyz/ (not entirely finished yet)
JocAnis is offline
AmXDusT
Member
Join Date: Feb 2019
Location: Italy / Albania
Old 10-16-2019 , 18:55   Re: Read file backwards
Reply With Quote #3

Not sure if that would work, but you can try recursion
AmXDusT is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-16-2019 , 19:16   Re: Read file backwards
Reply With Quote #4

It would work and is the simplest way to handle this, IMO.
__________________
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 10-16-2019 , 19:18   Re: Read file backwards
Reply With Quote #5

What "recursion" is? My english didn't figure out what you're trying to tell me haha
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-16-2019 , 19:30   Re: Read file backwards
Reply With Quote #6

Don't listen to him, just do as JocAnis suggested, this is not that complicated.
__________________
Bugsy is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 10-17-2019 , 00:02   Re: Read file backwards
Reply With Quote #7

Simplesmente, você le o arquivo normalmente de cima pra baixo e quando você for registrar o menu, comece do ultimo, pegando os valores decrescentes. Tipo, normalmente se utiliza o loop usando ++, é só você trocar pro --, tipo assim:

PHP Code:
// "i" will start with the MAX_VALUE readed, the loop will continue 'til the "i" be equal to or less than 0.
for(new ArraySize(g_arIniFileData);0;i--) 
E provavelmente, quando você for registrar o menu, mesmo usando o loop ao contrário, quando você for selecionar a opção ele ainda vai começar do 0 ao valor maximo que você registrar, então é necessário você passar a ID do item também pro handler, assim você pode saber que opção EXATA o jogador vai selecionar.

Basically:

Simply, you read the file normally, and when you'd create the menu, use the loop backwards, instead of increasing, you decrese the value, something like I showed. And probably, when you do register the menu, even using the reverse loop, after you select the option it'll still start from the 0 to the max value you registered without the menu_get_iteminfo, so you'll need to pass the ID of the item to the menu handler, with this, you'll be able to know which EXACT option the player would select.
__________________

Last edited by EFFx; 10-17-2019 at 00:11.
EFFx is offline
Send a message via Skype™ to EFFx
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-17-2019 , 00:17   Re: Read file backwards
Reply With Quote #8

Quote:
Originally Posted by EFFx View Post
Simplesmente, você le o arquivo normalmente de cima pra baixo e quando você for registrar o menu, comece do ultimo, pegando os valores decrescentes. Tipo, normalmente se utiliza o loop usando ++, é só você trocar pro --, tipo assim:

PHP Code:
// "i" will start with the MAX_VALUE readed, the loop will continue 'til the "i" be equal to or less than 0.
for(new ArraySize(g_arIniFileData);0;i--) 
E provavelmente, quando você for registrar o menu, mesmo usando o loop ao contrário, quando você for selecionar a opção ele ainda vai começar do 0 ao valor maximo que você registrar, então é necessário você passar a ID do item também pro handler, assim você pode saber que opção EXATA o jogador vai selecionar.

Basically:

Simply, you read the file normally, and when you'd create the menu, use the loop backwards, instead of increasing, you decrese the value, something like I showed. And probably, when you do register the menu, even using the reverse loop, after you select the option it'll still start from the 0 to the max value you registered without the menu_get_iteminfo, so you'll need to pass the ID of the item to the menu handler, with this, you'll be able to know which EXACT option the player would select.
for(new i = ArraySize(g_arIniFileData);i > 0;i--)

should be

for(new i = ArraySize(g_arIniFileData) - 1 ; i >= 0 ;i--)

or you will get an index out of bounds on the first pass using g_arIniFileData[ i ] and you also want to allow 0 to be accessed so >= 0 should be used.
__________________
Bugsy is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 10-17-2019 , 07:32   Re: Read file backwards
Reply With Quote #9

It worked, thanks to everyone who helped me, my mistake was at the end of the loop, because instead of decreasing I was adding value (inattention).
__________________
iceeedr is offline
Send a message via Skype™ to iceeedr
Natsheh
Veteran Member
Join Date: Sep 2012
Location: Muslim and proud!
Old 10-17-2019 , 08:50   Re: Read file backwards
Reply With Quote #10

Hello you also could use fseek

More info from the documentation

Spoiler
__________________
@Jailbreak MOD [Alot of features + API] 100% done !
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
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

Forum Jump


All times are GMT -4. The time now is 11:57.


Powered by vBulletin®
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Theme made by Freecode