Build Number [Question]!
#1

Hello guys i didn't know where to post this it seemed for me more then a discussion then a question because i want to know HOW exactly you can make it.

However my question is : let's say a script has a build number now every-time we compile we have to go through it and change it before we compile (+1) and to be honest it will be pain in the ass if you are compiling a lot.

Are there any ways that we can increase the build number every-time the compiler compiles the script ?
Reply
#2

That's a nice question and something I could see as useful, although sadly I don't think it could be done. Not through SAMP scripting alone at least.
Reply
#3

I suppose nothing automated is possible within Pawno itself, but I have seen one or two third party programs that I suppose could be modified for this feature. Look around the forums.
Reply
#4

Having a build number for a community/live server confuses players, just keep the version numbering system simple so players know when an update has been implemented.

If you're just doing this script for yourself/generally in private, you could (probably) make a batch script to +1 a version number somewhere in the Pawn file and then run the compiler for it.
Reply
#5

I read something like that in the forums two years ago but i really can't remember where, and when.

It really is useful for some case scenarios.
Reply
#6

I currently run SVN which keeps track of version numbers as long as I don't forget to actually log the changes. Then I run a batch file which copies the svn log to my server directory and creates a file in the scriptfiles directory with content like:
Code:
r48 | Vince | 2012-09-28 11:29:23 +0200 (vr, 28 sep 2012)
Whenever I want it, I can read that file with fread and display the information. I tried including the file at first, but that didn't work out because of errors.
Reply
#7

Quote:
Originally Posted by Vince
View Post
Whenever I want it, I can read that file with fread and display the information. I tried including the file at first, but that didn't work out because of errors.
I tried to create a batch file when someone runs / compiles the script in PAWNO that batch script will run and it will create a new file with a variable that is set to 0, the file would be .txt extension.

So everytime we hit run the batch runs and +1's the variable into the .txt file.

So later on we can use fread to read the file into our script.

However i bumped into some trouble in the batch file.
Reply
#8

I have written a code to help you :


Code:
@ECHO OFF
TITLE Compilation
:: Replace "Source.pwn" in the line below with the name of your Pawn script file. 
SET FileName="Source.pwn"
(
    ECHO.Option Explicit
    ECHO.Dim Fso, Text, x
    ECHO.ReDim Lines^(0^)
    ECHO.Set Fso = CreateObject^("Scripting.FileSystemObject"^)
    ECHO.Set Text = Fso.OpenTextFile^(%FileName%^)
    ECHO.While Not Text.AtEndOfStream
    ECHO.    x = Text.Line - 1
    ECHO.    ReDim Preserve Lines^(x^)
    ECHO.    Lines^(x^) = Text.ReadLine^(^)
    ECHO.    If InStr^(Lines^(x^), "const BuildNumber = "^) = 1 Then
    ECHO.        Lines^(x^) = "const BuildNumber = " ^& CInt^(Mid^(Lines^(x^), 21, Len^(Lines^(x^)^) - 21^)^) + 1 ^& ";"
    ECHO.    End If 
    ECHO.Wend
    ECHO.Text.Close^(^)
    ECHO.Fso.DeleteFile^(%FileName%^)
    ECHO.Set Text = Fso.CreateTextFile^(%FileName%^)
    ECHO.For Each x In Lines
    ECHO.    Text.WriteLine^(x^)
    ECHO.Next
    ECHO.Text.Close^(^)
) > Modify.vbs
CSCRIPT //NOLOGO Modify.vbs
DEL Modify.vbs
PAWNCC %FileName%
PAUSE > NUL

Save this as a batch file and put it in the same folder of pawncc.exe .



Then move your Pawn script file to that folder and add this to the top of it:


pawn Code:
const BuildNumber = 1;

The value of that constant will be increased by 1 and the compilation will happen each time you run the batch file .



I hope that I have helped .
Reply
#9

Quote:
Originally Posted by rjjj
View Post
I have written a code to help you :


Code:
@ECHO OFF
TITLE Compilation
:: Replace "Source.pwn" in the line below with the name of your Pawn script file. 
SET FileName="Source.pwn"
(
    ECHO.Option Explicit
    ECHO.Dim Fso, Text, x
    ECHO.ReDim Lines^(0^)
    ECHO.Set Fso = CreateObject^("Scripting.FileSystemObject"^)
    ECHO.Set Text = Fso.OpenTextFile^(%FileName%^)
    ECHO.While Not Text.AtEndOfStream
    ECHO.    x = Text.Line - 1
    ECHO.    ReDim Preserve Lines^(x^)
    ECHO.    Lines^(x^) = Text.ReadLine^(^)
    ECHO.    If InStr^(Lines^(x^), "const BuildNumber = "^) = 1 Then
    ECHO.        Lines^(x^) = "const BuildNumber = " ^& CInt^(Mid^(Lines^(x^), 21, Len^(Lines^(x^)^) - 21^)^) + 1 ^& ";"
    ECHO.    End If 
    ECHO.Wend
    ECHO.Text.Close^(^)
    ECHO.Fso.DeleteFile^(%FileName%^)
    ECHO.Set Text = Fso.CreateTextFile^(%FileName%^)
    ECHO.For Each x In Lines
    ECHO.    Text.WriteLine^(x^)
    ECHO.Next
    ECHO.Text.Close^(^)
) > Modify.vbs
CSCRIPT //NOLOGO Modify.vbs
DEL Modify.vbs
PAWNCC %FileName%
PAUSE > NUL

Save this as a batch file and put it in the same folder of pawncc.exe .



Then move your Pawn script file to that folder and add this to the top of it:


pawn Code:
const BuildNumber = 1;

The value of that constant will be increased by 1 and the compilation will happen each time you run the batch file .



I hope that I have helped .
Thanks mate it worked, FINALLY!

Here eat a virtual cookie :P

EDIT: Can you tell me what exactly you did.
Reply
#10

Quote:
Originally Posted by [Lexi]
View Post
Thanks mate it worked, FINALLY!

Here eat a virtual cookie :P

EDIT: Can you tell me what exactly you did.
It's called Batch programming/scripting.
Reply
#11

Quote:
Originally Posted by Vince
Посмотреть сообщение
I currently run SVN which keeps track of version numbers as long as I don't forget to actually log the changes. Then I run a batch file which copies the svn log to my server directory and creates a file in the scriptfiles directory with content like:
.
I'm pretty sure SVN has an inbuilt feature for that (properties/keywords), but I'm not sure of the syntax. Plus that's just commit number, not build number.

Quote:
Originally Posted by Sniper Kitty
Посмотреть сообщение
It's called Batch programming/scripting.
No it isn't, all that code does it generate a VB script and run that instead.

Anyway, I've been trying to think of an elegant way to do this, but can't (I even checked the documentation and there was nothing). So it does look like you'll have to use a custom script. Anyway, this is what things called "makefiles" are explicitly designed for - you might want to look them up!
Reply
#12

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
No it isn't, all that code does it generate a VB script and run that instead.
http://www.dreamincode.net/forums/to...torial-part-1/
http://www.youtube.com/watch?v=PPsPBX7-BoQ

Correct me if I'm wrong, but that code looks ALOT similar to these 'Batch Tutorials'... No?
Reply
#13

Well yes, sort of:

pawn Код:
) > Modify.vbs
CSCRIPT //NOLOGO Modify.vbs
That is a batch script, but all it does is print some lines to a file, save it as a .VBS file, then run that file instead (even though everything they want can be done in pure batch scripting). "echo" is like "print", or in this case like "fwrite".
Reply
#14

Okay =]
Reply
#15

Quote:
Originally Posted by Sniper Kitty
Посмотреть сообщение
It's called Batch programming/scripting.
Why are you Quoting me ? I know what is it!
Reply
#16

Quote:
Originally Posted by [Lexi]
Посмотреть сообщение
Thanks mate it worked, FINALLY!

Here eat a virtual cookie :P

EDIT: Can you tell me what exactly you did.
I programmed the batch file to create another code file, made with VBScript, which would loop through the lines of the Pawn script file, storing each of them in a dynamic array .



When doing this, if the declaration of BuildNumber was found, its value would be increased through string manipulation, variable subtype conversion and arithmetic operation.



Then the .pwn file would get deleted and another one would get made using the lines stored in that array .



Finally, the Batch Script code would run the Pawn compiler.



I hope that I have helped .
Reply
#17

Quote:
Originally Posted by rjjj
Посмотреть сообщение
I programmed the batch file to create another code file, made with VBScript, which would loop through the lines of the Pawn script file, storing each of them in a dynamic array .



When doing this, if the declaration of BuildNumber was found, its value would be increased through string manipulation, variable subtype conversion and arithmetic operation.



Then the .pwn file would get deleted and another one would get made using the lines stored in that array .



Finally, the Batch Script code would run the Pawn compiler.



I hope that I have helped .
Thanks mate i already gave you a virtual cookie, so i can now
Reply
#18

Quote:
Originally Posted by rjjj
Посмотреть сообщение
I programmed the batch file to create another code file, made with VBScript, which would loop through the lines of the Pawn script file, storing each of them in a dynamic array .



When doing this, if the declaration of BuildNumber was found, its value would be increased through string manipulation, variable subtype conversion and arithmetic operation.



Then the .pwn file would get deleted and another one would get made using the lines stored in that array .



Finally, the Batch Script code would run the Pawn compiler.



I hope that I have helped .
Maybe I didn't understand, but why to recreate all .pwn file? It can be very huge. You can just create another file, add "const BuildNumber = 1" to that file and do the same, what you are doing for .pwn file. And of course, include that file to main gamemode file.
Reply
#19

Quote:
Originally Posted by zgintasz
Посмотреть сообщение
Maybe I didn't understand, but why to recreate all .pwn file? It can be very huge. You can just create another file, add "const BuildNumber = 1" to that file and do the same, what you are doing for .pwn file. And of course, include that file to main gamemode file.
That's the way I would do it, in fact you can even put half the declaration in one file and just the number in another.
Reply
#20

Quote:
Originally Posted by zgintasz
Посмотреть сообщение
Maybe I didn't understand, but why to recreate all .pwn file? It can be very huge. You can just create another file, add "const BuildNumber = 1" to that file and do the same, what you are doing for .pwn file. And of course, include that file to main gamemode file.
I have just tried to make a program which could automate the original poster's work .



Well, if that person wants a more optimised code, your trick is able to solve his problem .



I hope that I have helped .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)