Template:CodeSnip

From PZwiki
Notebook.pngTemplate Documentation

This template is an alternate way of using <syntaxhighlight> with some added functionality.

Usage

This template is used to show syntax-highlighted text.

This may be used for articles with segments of code extracted from the game files.

Parameters

1 code
The code to be displayed.
2 lang
Defines the programming language for the syntax highlighting. Highlighting uses the pygments library. Default to text.
source
Name of the source file. Some script files will automatically determine the path.
path
The file path of the source file. Will not display if source is empty. Default to ProjectZomboid\media\scripts\.
line
If true, line numbers will be displayed.
start
Line number to start at. line must be defined.
retrieved
If true, will add {{Retrieved}}. Refer to that template for parameters.

Examples

HTML language example

{{CodeSnip
| lang = html
| code = <div style="font-weight:bold; color:#3434ff;">
Some text goes here.<br>More text here
</div>
}}


<div style="font-weight:bold; color:#3434ff;">
Some text goes here.<br>More text here
</div>

Source example

{{CodeSnip|source=newitems.txt}}

Source: ProjectZomboid\media\scripts\newitems.txt


Source and file path example

{{CodeSnip
| source = IsoPlayer.class
| path = ProjectZomboid\zombie\characters
}}

Source: ProjectZomboid\zombie\characters\IsoPlayer.class


Item code with source and java language

{{CodeSnip
| lang = java
| source = items_weapons.txt
| code =     item Glue
    {
        DisplayCategory = Material,
        Weight	=	0.1,
        Type	=	Drainable,
        UseDelta	=	0.2,
        UseWhileEquipped	=	FALSE,
        DisplayName	=	Glue,
        Icon	=	Glue,
        Tooltip = Tooltip_FixItems,
        SurvivalGear = TRUE,
        WorldStaticModel = Glue,
        Tags = Glue,
    }
}}

Source: ProjectZomboid\media\scripts\items_weapons.txt

item Glue
    {
        DisplayCategory = Material,
        Weight	=	0.1,
        Type	=	Drainable,
        UseDelta	=	0.2,
        UseWhileEquipped	=	FALSE,
        DisplayName	=	Glue,
        Icon	=	Glue,
        Tooltip = Tooltip_FixItems,
        SurvivalGear = TRUE,
        WorldStaticModel = Glue,
        Tags = Glue,
    }

Java code with source and path defined

{{CodeSnip
| lang = java
| source = RDSPrisonEscape.class
| path = ProjectZomboid\zombie\randomizedWorld\randomizedDeadSurvivor
| code =     public RDSPrisonEscape() {
        this.name = "Prison Escape";
        this.setChance(3);
        this.setMaximumDays(90);
        this.setUnique(true);
    }
}}

Source: ProjectZomboid\zombie\randomizedWorld\randomizedDeadSurvivor\RDSPrisonEscape.class

public RDSPrisonEscape() {
        this.name = "Prison Escape";
        this.setChance(3);
        this.setMaximumDays(90);
        this.setUnique(true);
    }

Item code with source, java language, line number and {{Retrieved}}

{{CodeSnip
| lang = java
| line = true
| start = 92
| source = items.txt
| retrieved = true
| version = 41
| incver = 78.16
| code =   item BucketEmpty
    {
        DisplayCategory = WaterContainer,
        Weight	=	1,
        CanStoreWater	=	TRUE,
        Type	=	Normal,
        DisplayName	=	Bucket,
        Icon	=	MetalBucket,
        ReplaceOnUseOn = WaterSource-BucketWaterFull,
        MetalValue = 20,
        RainFactor = 1,
        Tooltip = Tooltip_item_RainFromGround,
        EatType = Bucket,
        SurvivalGear = TRUE,
        WorldStaticModel = Bucket_Ground,
    }
}}

Source: ProjectZomboid\media\scripts\items.txt

Retrieved: Build 41.78.16
item BucketEmpty
    {
        DisplayCategory = WaterContainer,
        Weight	=	1,
        CanStoreWater	=	TRUE,
        Type	=	Normal,
        DisplayName	=	Bucket,
        Icon	=	MetalBucket,
        ReplaceOnUseOn = WaterSource-BucketWaterFull,
        MetalValue = 20,
        RainFactor = 1,
        Tooltip = Tooltip_item_RainFromGround,
        EatType = Bucket,
        SurvivalGear = TRUE,
        WorldStaticModel = Bucket_Ground,
    }

How to translate

This template doesn't need to/shouldn't be translated, but you can translate the documentation of this template with the following steps:

  1. Create a subpage of this template with the language code of the language you want to translate to.
  2. Copy the code wrapped in the <noinclude> tag in this template into the page you created.
    {{Translation guide}} template should be removed from the translated documentation.
  3. Translate the page according to the translation requirements of normal pages.

See also

Editors can experiment in this template's sandbox.