AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Auto increment number (https://forums.alliedmods.net/showthread.php?t=237951)

Buckshot 04-01-2014 09:13

Auto increment number
 
How would you do this in pawn when for example writing to files? Each entry in the file has it's own number. Like the "id" column which you usually see in SQL. First one 1,second 2.. and it keeps going. I can't figure out how, since this would reset when the server is restarted, you'd need to save something in a file? You could save the current number, if for example 2 entries have been added, and the map changes, it is going to write the number 2 to the txt, and when the next entry comes in the next map, it will read the txt file's number and take that and add 2++ as the incremented number for the next entry "3".. But it feels abit unecessary to make a .txt file just to type ONE single number. There's gotta be a better way?

ironskillz1 04-01-2014 09:48

Re: Auto increment number
 
nVault?

Neeeeeeeeeel.- 04-01-2014 10:04

Re: Auto increment number
 
PHP Code:

write_file("filename.txt""number here"0); 


Buckshot 04-01-2014 10:07

Re: Auto increment number
 
Quote:

Originally Posted by Neeeeeeeeeel.- (Post 2118782)
PHP Code:

write_file("filename.txt""number here"0); 


That does not autoincrement though... that just inserts the number i entered there in the text. If i make +1 every time theres a new entry, this number will reset when the server is restarted. I don't think you read the description fully.. The files entries are gonna be like this, with the correct number every entry, even if the server restarts or not:

Code:

1: Random info
2: More random info
3: Even more random info
4: more..
5: aaand more..

if i would use this method, it could look like this eventually after a few map changes and restarts:

Code:

1: Random info
2: More random info
/* Map changes a while after entry 2 is entered, and this is what happens*/
1: Random info:
2: More random info
......
/* It just starts over from the beginning*/


YamiKaitou 04-01-2014 10:10

Re: Auto increment number
 
Why not use SQLite?

Buckshot 04-01-2014 10:15

Re: Auto increment number
 
Quote:

Originally Posted by YamiKaitou (Post 2118787)
Why not use SQLite?

I wasn't planning on using SQL for this, since i am just writing to a HTML file existing in my cstrike dir.. It would not be a problem to autoincrement with sql, but it is unecessary to use databases for such small tasks that i am currently doing. Just looking for an easy method to autoincrement without sql. The method i'm currently using is:


Each time i'm writing to a file i'm checking this first

got a variable named num
Read number in file currentrow.txt and place that in variable num
num++
remove number in currentrow.txt and replace with variable num's value which is the previous value +1

and i use the nums value for entry number autoincrement, so nums value goes up by +1 each time i enter a new row in my other txt file.

Seems way too complicated. Just thought there might be an easier way, without using sql.. But i guess it's the only way?

YamiKaitou 04-01-2014 10:23

Re: Auto increment number
 
Use vault to save the last used number then

fysiks 04-01-2014 11:24

Re: Auto increment number
 
Neel's solution is easy enough. Simply read the file when the server starts and set that as your starting number.


All times are GMT -4. The time now is 06:02.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.