Searching in a text file
Okay, I already read a lot of articles about working with files in pawn and I'm sure it's out there somewhere but I'm frustrated of trying and failing at this so can someone help me please?
I have a text file and each line is consists of a map name, and a number, So it would be something like this: Code:
de_dust2 123 |
Re: Searching in a text file
Use a trie to get the entry ( the map name ), then all goes from itself: entry = value ( number of certain map ). You can use an iterator to find the entry, when the entry is equal with your search, stop the function and so on.
|
Re: Searching in a text file
What part are you having issues with? You should provide the code that you tried so we can help you with your code.
There are several ways to do this and the best method will depend on how you are going to use the data. If you are looking up only for the current map and using that value for that map, you generally don't need to store the entire file in a variable. In this case, you would just loop through the lines of the file until your first argument matches the current map name and then you would grab the value that goes with it. If all of the data is needed at any time, you should store all the data in variables in the plugin and then you'd look through that data to get what you need. There are several ways to do this, again depending on how you plan to use the data. Some are more complex than others. Post your code and maybe explain how you're going to use the data so that we can help you out. Quote:
|
Re: Searching in a text file
Quote:
I'm trying to find the world record for the current map, It's for a kreedz server (I have them all stored in a file, the format is almost the same but I'll copy the whole thing so you can see for yourself) And no, a trie would not be helpful since I don't need information about other maps, I just need to save the decimal time of the current map's world record in a variable so I'd be able to do stuff with it, for example show how much a player's record is slower than the WR. And about my code, I failed to come up with anything that worked, I failed to figure out how that "Looping thru the data and searching for the first argument that matches up with current map" works. Code:
8b1_brickngrass 229.39 Chasquido ar 642 |
Re: Searching in a text file
Well, in the first post you said "I already read a lot of articles about working with files in pawn" but I no longer believe that this is actually a true statement since you have not shown any effort to read a file.
I actually found one tutorial that does nearly exactly what you're wanting to do. The thread is here and you should look for the filereadtest() function that uses the "new file commands" (fopen, fgets, fclose). If you are unable to get it working after implementing your code based on this example, attach your .sma file so that we can help you make it work. |
Re: /wr Plugin (Formerly: Searching in a text file)
1 Attachment(s)
Hey, I figured it out by myself and it seems like it's working so I just changed the post title so if anybody had the same problem they could read it and I hope that it could help them.
Code:
#include <amxmodx>I'd appreciate if someone could check it and see if I made any mistakes. |
Re: /wr Plugin (Formerly: Searching in a text file)
Code:
Code:
Code:
|
Re: /wr Plugin (Formerly: Searching in a text file)
Code:
/* Define array as static because you don't use it so much, so a plus in optimizing. */2. This has been discussed for hundreds of times already. |
Re: /wr Plugin (Formerly: Searching in a text file)
Quote:
Code:
A variable declared with the keyword "static" instead of "new" operates in the same way a global does (it is created only once) but the variable is local to the function; this means the code is much easier to read, while drastically improving speed just like a global variable.Quote:
|
Re: /wr Plugin (Formerly: Searching in a text file)
A "dynamic" variable will be freed at the end of the function whereas a static one when the script finishes running. There is no optimization whatsoever in this case, you're just keeping it uselessly.
|
| All times are GMT -4. The time now is 13:44. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.