StrParam

From ZDoom Wiki
(Redirected from Strparam)
Jump to navigation Jump to search

int StrParam(item(s));

Usage

StrParam will create a new string formatted based upon the same method for print or log. This string will only exist for 1 tic, so a delay will nullify it. As of revision r4295, strings generated by StrParam, GetCVarString and GetUserCVarString will last for as long as they need to, rather than for 1 tic.

This can be used to concatenate multiple ACS strings.

Return Value

The return value is the string table index of the new string.


Error.gif
Warning: This feature has at least one use case where the outcome is indeterminate. This feature can break demo and multiplayer sync if an indeterminate result is used to modify the playsim (anything that uses the random number generator, modify level geometry, spawn obstacles, monsters, or powerups, and so on). Usage of the feature in conjunction with non-playsim related features, such as displaying a HudMessage, is safe.

If string cast types l, k, or n are used, the resulting string may vary based on client settings. Typically this will not cause issues unless the result in combined with some other string operation and that is used to affect the playsim.

Example

str mapname = "hangar";

script 3 enter
{
// you can also assign it to a variable,
// but its contents are only valid until this tick ends if you are
// using a version prior to revision 4295
    int keyObject = strparam(s:mapname, s:"key"); // would create "hangarkey"
    if (CheckInventory(keyObject))
    {
        TakeInventory(keyObject, 1);
    }
    else
    {
        print(s:"You require ", s:keyObject);
        terminate; // after ending the script, you cannot expect the value in keyObject to point to a valid string anymore
                   // on versions prior to r4295
    }
    ACS_Execute(120,0,10);
    // ACS_Execute will not execute code during this tick.
    // keyObject will not exist anymore when it starts running script 120.
    // if you are using a version prior to r4295

    delay(1); // now a tick will pass. any dynamic strings generated before this delay will be invalid once execution resumes on
              // versions prior to r4295
    /*
        no keyObject here on pre-r4295
    */
}