Raised This Month: $ Target: $400
 0% 

Auto increment number


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-01-2014 , 09:13   Auto increment number
Reply With Quote #1

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?
__________________
PM me for private work.



Last edited by Buckshot; 04-01-2014 at 09:27.
Buckshot is offline
Send a message via Skype™ to Buckshot
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 04-01-2014 , 09:48   Re: Auto increment number
Reply With Quote #2

nVault?
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 04-01-2014 , 10:04   Re: Auto increment number
Reply With Quote #3

PHP Code:
write_file("filename.txt""number here"0); 
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-01-2014 , 10:07   Re: Auto increment number
Reply With Quote #4

Quote:
Originally Posted by Neeeeeeeeeel.- View Post
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*/
__________________
PM me for private work.



Last edited by Buckshot; 04-01-2014 at 10:13.
Buckshot is offline
Send a message via Skype™ to Buckshot
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-01-2014 , 10:10   Re: Auto increment number
Reply With Quote #5

Why not use SQLite?
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Buckshot
Senior Member
Join Date: Mar 2014
Location: Sweden
Old 04-01-2014 , 10:15   Re: Auto increment number
Reply With Quote #6

Quote:
Originally Posted by YamiKaitou View Post
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?
__________________
PM me for private work.



Last edited by Buckshot; 04-01-2014 at 10:27.
Buckshot is offline
Send a message via Skype™ to Buckshot
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-01-2014 , 10:23   Re: Auto increment number
Reply With Quote #7

Use vault to save the last used number then
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-01-2014 , 11:24   Re: Auto increment number
Reply With Quote #8

Neel's solution is easy enough. Simply read the file when the server starts and set that as your starting number.
__________________
fysiks is offline
Reply



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 06:02.


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