Read file backwards
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. |
Re: Read file backwards
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 :o
|
Re: Read file backwards
Not sure if that would work, but you can try recursion
|
Re: Read file backwards
It would work and is the simplest way to handle this, IMO.
|
Re: Read file backwards
What "recursion" is? My english didn't figure out what you're trying to tell me haha
|
Re: Read file backwards
Don't listen to him, just do as JocAnis suggested, this is not that complicated.
|
Re: Read file backwards
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:
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. |
Re: Read file backwards
Quote:
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. |
Re: Read file backwards
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).
|
Re: Read file backwards
Hello you also could use fseek
More info from the documentation
Spoiler
|
All times are GMT -4. The time now is 20:29. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.