|
Templates |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
StatsGen produces all of it's outputs by processing templates. Templates are essentially HTML files with embedded Code that StatsGen uses to perform actions.
StatsGen code is embedded in $$ symbols, e.g. the following piece of template
<HTML>
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Templates: Variables |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Variables are alphanumeric (letters and numbers) tags that hold values. You assign variables values by putting the = character after them. After the = character you can place a literals (value surrounded by " characters), functions or other variables. e.g. $$variable1="statsgen"$$ $$variable2=colouredtext2html("^1s^7tats^1g^7en")$$ $$variable3=variable1$$ Sometimes you may wish to embed variables or function results into other StatsGen template code. You do this by surrounding the embedded values with %% characters. e.g. $$index="2"$$ $$variable%%index%%="StatsGen%%index%%$$" This is the equivalent of $$variable2="StatsGen2"$$ Records retrieved from the database (see the loop command later) can have their fields retrieved by separating the record variable and the field name with a . (dot) character. e.g. $$variable1=player.name$$ This sets the variable1 value to the field name of the database record player. You can also use the column index instead of the field name. e.g. $$variable1=player.1$$ This sets the variable1 value to the first field of the database record player. Writing out the contents of variables or functions is achieved by just specifying their name. e.g. $$variable1$$ This writes out the contents of variable1 to the currently open output file. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Templates: Program Flow |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
StatsGen has two program flow capabilities, if, else, endif and the loop, endloop commands.if, else and endifgives you the ability to make decisions based upon variable contents so that you only execute certain sections of templates under specific conditions. The code is structured as follows. if (condition) ![]() endif or if (condition) ![]() else ![]() endif condition is in the following form. variable1 operator variable2 There are 6 operators
<HTML> <H1> $$if (player.name EQUALS "nazarine")$$ ![]() $$else$$ ![]() $$endif$$ </H1> </HTML> A note on comparisons: When comparing 2 variables together StatsGen does it's best to determine if the 2 variables are numbers or text. If they are both numbers then it compares them mathematically (2.0 < 10.0) otherwise it compares them alphabetically ("shaun" > "nazarine") DO NOT forget to close if commands with an associated endif otherwise StatsGen will give you odd results loop, endloopNow we are getting to the interesting bits. When StatsGen processes the logfiles it stores the results in a database. The loop command allows you to search that database using SQL statements and step through each record retrieved one at a time.loop row as <recordvariable> index as <indexvariable> <SQL> endloop The SQL is any SELECT statement that SQLITE3 can understand. Each record retrieved is stored in the recordvariable for later interrogation. The indexvariable gets the current record count (starting at 1) for the loop. Loops are terminated by endloop. Forgetting to terminate a loop with endloop could cause unforseen results and make StatsGen run out of resources. Using a combination of SQL and all the information stored in the database many unique and interesting web pages can be produced, from the very simple to the very complex. Example $$openfile playerlist.html$$ <HTML> <H1>Player List</H1> $$loop row as player index as playernumber select * from players order by name$$ Player $$playernumber$$ is called $$player.name$$<br> $$endloop$$ </HTML> $$closefile$$ |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Templates: ProceduresProcedures just execute commands but unlike functions, return no values. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Templates: Functions / VariablesFunctions return a value, typically used as part of writing out the contents of a file or as part of another StatsGen function / command |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|